diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index 90b0e44f52..b213653387 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -779,8 +779,8 @@ namespace Slang SLANG_ASSERT(constraintDecl2); return TryUnifyTypes(constraints, unifyCtx, - constraintDecl1.getDecl()->getSup().type, - constraintDecl2.getDecl()->getSup().type); + getSup(m_astBuilder, constraintDecl1), + getSup(m_astBuilder, constraintDecl2)); } } diff --git a/tests/language-feature/generics/nested-gen-value-param-inference-2.slang b/tests/language-feature/generics/nested-gen-value-param-inference-2.slang new file mode 100644 index 0000000000..038329e878 --- /dev/null +++ b/tests/language-feature/generics/nested-gen-value-param-inference-2.slang @@ -0,0 +1,41 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type + +interface IValueGeneric {} +struct ValGenericImpl : IValueGeneric {} + +struct NestedValueGeneric> +{ + int x; +} + +void acceptor>(NestedValueGeneric x) +{ + outputBuffer[0] = D + x.x; +} + +extension> NestedValueGeneric +{ + void foo() + { + acceptor(this); + } +} +void test2(NestedValueGeneric<2, ValGenericImpl<2>> x) +{ + // 'foo' should be a member of 'NestedValueGeneric<2, ValGenericImpl<2>>' through + // the extension above. + x.foo(); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + NestedValueGeneric<2, ValGenericImpl<2>> x; + x.x = 1; + test2(x); + // CHECK: 3 +} \ No newline at end of file diff --git a/tests/language-feature/generics/nested-gen-value-param-inference.slang b/tests/language-feature/generics/nested-gen-value-param-inference.slang new file mode 100644 index 0000000000..cf7e5faf8d --- /dev/null +++ b/tests/language-feature/generics/nested-gen-value-param-inference.slang @@ -0,0 +1,32 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-vk -compute -shaderobj -output-using-type + +interface IValueGeneric {} +struct ValGenericImpl : IValueGeneric {} + +struct NestedValueGeneric> +{ + int x; +} + +void acceptor>(NestedValueGeneric x) +{ + outputBuffer[0] = D + x.x; +} +void test(NestedValueGeneric<2, ValGenericImpl<2>> x) +{ + // Test that we can correctly infer acceptor.D and acceptor.S from `x`. + acceptor(x); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + NestedValueGeneric<2, ValGenericImpl<2>> x; + x.x = 1; + test(x); + // CHECK: 3 +} \ No newline at end of file