From 60b66c309075e91824aef69a153e304561ca6041 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 12 Jun 2025 14:59:27 -0500 Subject: Fix issue of missing scope for 'Differential' type (#7433) * Fix issue of missing scope for 'Differential' type When we synthesize the struct decl for Differential type, we should add the ownedScope for this decl, because the scope is used in lots of locations in the following synthesized processes, e.g. constructor synthesize. And that could cause surprising behavior, e.g. the 'this' expression could access the members of parent struct decl. Fix the issue by adding the scope. The containerDecl will be the Differential struct decl itself, parent scope will be the parent struct. * Add a unit-test --- source/slang/slang-check-expr.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index a530eb8f0..43987132e 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -674,6 +674,9 @@ Expr* SemanticsVisitor::maybeUseSynthesizedDeclForLookupResult( conformanceDecl->base.type = m_astBuilder->getDiffInterfaceType(); structDecl->addMember(conformanceDecl); structDecl->parentDecl = parent; + structDecl->ownedScope = m_astBuilder->create(); + structDecl->ownedScope->containerDecl = structDecl; + structDecl->ownedScope->parent = getScope(parent); synthesizedDecl = structDecl; auto typeDef = m_astBuilder->create(); -- cgit v1.2.3