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-decl.cpp | 50 +++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'source/slang/slang-check-decl.cpp') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 580ad8402..c0253fd2c 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -1543,18 +1543,48 @@ namespace Slang }; // Make the Differential type itself conform to `IDifferential` interface. - auto inheritanceIDiffernetiable = m_astBuilder->create(); - inheritanceIDiffernetiable->base.type = m_astBuilder->getDiffInterfaceType(); - inheritanceIDiffernetiable->parentDecl = aggTypeDecl; - aggTypeDecl->members.add(inheritanceIDiffernetiable); + bool hasDifferentialConformance = false; + for (auto inheritanceDecl : aggTypeDecl->getMembersOfType()) + { + if (auto declRefType = as(inheritanceDecl->base.type)) + { + if (declRefType->declRef == m_astBuilder->getDifferentiableInterface()) + { + hasDifferentialConformance = true; + break; + } + } + } + if (!hasDifferentialConformance) + { + auto inheritanceIDiffernetiable = m_astBuilder->create(); + inheritanceIDiffernetiable->base.type = m_astBuilder->getDiffInterfaceType(); + inheritanceIDiffernetiable->parentDecl = aggTypeDecl; + aggTypeDecl->members.add(inheritanceIDiffernetiable); + } // The `Differential` type of a `Differential` type is always itself. - auto assocTypeDef = m_astBuilder->create(); - assocTypeDef->nameAndLoc.name = getName("Differential"); - assocTypeDef->type.type = satisfyingType; - assocTypeDef->parentDecl = aggTypeDecl; - assocTypeDef->setCheckState(DeclCheckState::Checked); - aggTypeDecl->members.add(assocTypeDef); + bool hasDifferentialTypeDef = false; + for (auto member : aggTypeDecl->members) + { + if (auto name = member->getName()) + { + if (name->text == "Differential") + { + hasDifferentialTypeDef = true; + break; + } + } + } + if (!hasDifferentialTypeDef) + { + auto assocTypeDef = m_astBuilder->create(); + assocTypeDef->nameAndLoc.name = getName("Differential"); + assocTypeDef->type.type = satisfyingType; + assocTypeDef->parentDecl = aggTypeDecl; + assocTypeDef->setCheckState(DeclCheckState::Checked); + aggTypeDecl->members.add(assocTypeDef); + } // Go through all members and collect their differential types. // Go through super types. -- cgit v1.2.3