diff options
| author | Yong He <yonghe@outlook.com> | 2023-03-21 20:03:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-21 20:03:12 -0700 |
| commit | 83876733d69582eec6bad26af64a651d40fa43aa (patch) | |
| tree | 641edb23ee4d656b198e1cc840470702f3ac391d /source/slang/slang-check-decl.cpp | |
| parent | 5d2c5dd9f748d728abf2a4361fca71a7f9ec65b6 (diff) | |
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 <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
| -rw-r--r-- | source/slang/slang-check-decl.cpp | 50 |
1 files changed, 40 insertions, 10 deletions
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<InheritanceDecl>(); - inheritanceIDiffernetiable->base.type = m_astBuilder->getDiffInterfaceType(); - inheritanceIDiffernetiable->parentDecl = aggTypeDecl; - aggTypeDecl->members.add(inheritanceIDiffernetiable); + bool hasDifferentialConformance = false; + for (auto inheritanceDecl : aggTypeDecl->getMembersOfType<InheritanceDecl>()) + { + if (auto declRefType = as<DeclRefType>(inheritanceDecl->base.type)) + { + if (declRefType->declRef == m_astBuilder->getDifferentiableInterface()) + { + hasDifferentialConformance = true; + break; + } + } + } + if (!hasDifferentialConformance) + { + auto inheritanceIDiffernetiable = m_astBuilder->create<InheritanceDecl>(); + 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<TypeDefDecl>(); - 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<TypeDefDecl>(); + 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. |
