From 977e4b21d69406b0b68c5963f50489d7433db830 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 11 Jul 2024 13:46:21 -0400 Subject: Fix issue with synthesizing `Differential` type for self-differential generic types (#4602) * Fix issue with synthesizing `Differential` type for self-differential generic types The problem was that we were using the type that was performing the lookup for `.Differential` which can have substitutions based on the local context where the decl is being referenced. We need to synthesize the type local to the decl itself * Update auto-differential-type-generic.slang --- source/slang/slang-check-expr.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index ee36a21fb..f60ead1e9 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -638,7 +638,12 @@ namespace Slang auto typeDef = m_astBuilder->create(); typeDef->nameAndLoc.name = item.declRef.getName(); typeDef->parentDecl = parent; - typeDef->type.type = subType; + + // Compute the decl's type as if it is referred to from itself. This is important because + // subType may have substitutions from the context it is used in, while this synthesis step + // is local to the decl. + // + typeDef->type.type = calcThisType(subType->getDeclRef().getDecl()->getDefaultDeclRef()); synthesizedDecl = parent; -- cgit v1.2.3