From 83876733d69582eec6bad26af64a651d40fa43aa Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 21 Mar 2023 20:03:12 -0700 Subject: Fix associated type resolution bug. (#2719) * Fix associated type resolution bug. * Fix. * Fix language server hinting messed up by breadcrumb nodes. --------- Co-authored-by: Yong He --- source/slang/slang-check-expr.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-check-expr.cpp') diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index 8d8a72dd6..bfad1dbfe 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -487,12 +487,25 @@ namespace Slang switch (builtinAssocTypeAttr->kind) { case BuiltinRequirementKind::DifferentialType: - synthesizedDecl = m_astBuilder->create(); + { + auto structDecl = m_astBuilder->create(); + auto conformanceDecl = m_astBuilder->create(); + conformanceDecl->base.type = m_astBuilder->getDiffInterfaceType(); + conformanceDecl->parentDecl = structDecl; + structDecl->members.add(conformanceDecl); + + synthesizedDecl = structDecl; + auto typeDef = m_astBuilder->create(); + typeDef->nameAndLoc.name = getName("Differential"); + auto declRef = createDefaultSubstitutionsIfNeeded(m_astBuilder, this, DeclRef(structDecl, nullptr)); + typeDef->type.type = m_astBuilder->getOrCreateDeclRefType(declRef.decl, declRef.substitutions); + typeDef->parentDecl = structDecl; + structDecl->members.add(typeDef); + } break; default: - break; + return nullptr; } - synthesizedDecl = m_astBuilder->create(); synthesizedDecl->parentDecl = parent; synthesizedDecl->nameAndLoc.name = item.declRef.getName(); synthesizedDecl->loc = parent->loc; @@ -645,6 +658,15 @@ namespace Slang default: SLANG_UNREACHABLE("all cases handle"); } + if (getShared()->isInLanguageServer()) + { + // Don't make breadcrumb nodes carry any source loc info, + // as they may confuse language server functionalities. + if (bb) + { + bb->loc = SourceLoc(); + } + } } return ConstructDeclRefExpr(item.declRef, bb, loc, originalExpr); -- cgit v1.2.3