From c65c4b5a8433177e8f836dd399c195150d2b463b Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 9 Sep 2024 12:31:06 -0700 Subject: [PATCH] Fix inccorect dropping of declref during Unification of DeclaredSubtypeWitness. --- source/slang/slang-check-constraint.cpp | 4 +-- .../nested-gen-value-param-inference.slang | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 tests/language-feature/generics/nested-gen-value-param-inference.slang 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.slang b/tests/language-feature/generics/nested-gen-value-param-inference.slang new file mode 100644 index 0000000000..e249e7e713 --- /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) +{ + // could not specialize generic for arguments of type (NestedValueGeneric<2, ValGenericImpl<2>>) + 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