From 7ce7bb3364cf84f5a9247358dcec79ba5aef8572 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 1 Oct 2024 09:34:31 -0700 Subject: Fix crash when compiling associatedtypes with generic interface constraints. (#5200) * Fix crash when compiling associatedtypes with generic interface constraints. * delete hlsl.meta.slang.temp.h. * Fix. --- .../generics/generic-assoc-type-constraint.slang | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/language-feature/generics/generic-assoc-type-constraint.slang (limited to 'tests') diff --git a/tests/language-feature/generics/generic-assoc-type-constraint.slang b/tests/language-feature/generics/generic-assoc-type-constraint.slang new file mode 100644 index 000000000..6b9aa1b01 --- /dev/null +++ b/tests/language-feature/generics/generic-assoc-type-constraint.slang @@ -0,0 +1,44 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -shaderobj -output-using-type +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj -output-using-type + +// Test that an associated type can be constrained to a generic interface. + + +interface IB +{ + int bar(); +} + +interface IA +{ + associatedtype B : IB; + B getB(); +} + +struct BImpl : IB +{ + int bar() { return x; } +} + +struct AImpl : IA +{ + typealias B = BImpl; + B getB() { BImpl b = {}; return b; } +} + +int test>(T t) +{ + T.B bb = t.getB(); + return bb.bar(); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + AImpl<5> a; + // CHECK: 5 + outputBuffer[0] = test(a); +} \ No newline at end of file -- cgit v1.2.3