diff options
| author | Yong He <yonghe@outlook.com> | 2018-01-14 16:22:11 -0500 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2018-01-14 16:22:11 -0500 |
| commit | d33e6b7475a87d5a62101afc81813e9c9e458a70 (patch) | |
| tree | 7ed6bc875ee0872f35218e7c76d18bf5bcad02ec /source/slang/check.cpp | |
| parent | d4dab2cd3a409411c2d7caed01fc02a0fd3e8450 (diff) | |
allow extension of a concrete type to implement additional interface
Also support the scenario that the extension declares conformance to interface I, and a method M in I is already supported by the base implementation.
Diffstat (limited to 'source/slang/check.cpp')
| -rw-r--r-- | source/slang/check.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 6c484b493..6b8331060 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1794,7 +1794,7 @@ namespace Slang // `requiredMemberDeclRef` is a required member of // the interface. RefPtr<Decl> findWitnessForInterfaceRequirement( - DeclRef<AggTypeDecl> typeDeclRef, + DeclRef<AggTypeDeclBase> typeDeclRef, InheritanceDecl* inheritanceDecl, DeclRef<InterfaceDecl> interfaceDeclRef, DeclRef<Decl> requiredMemberDeclRef, @@ -1833,11 +1833,9 @@ namespace Slang // Make sure that by-name lookup is possible. buildMemberDictionary(typeDeclRef.getDecl()); - - Decl* firstMemberOfName = nullptr; - typeDeclRef.getDecl()->memberDictionary.TryGetValue(name, firstMemberOfName); - - if (!firstMemberOfName) + auto lookupResult = lookUpLocal(getSession(), this, name, typeDeclRef); + + if (!lookupResult.isValid()) { getSink()->diagnose(inheritanceDecl, Diagnostics::typeDoesntImplementInterfaceRequirement, typeDeclRef, requiredMemberDeclRef); return nullptr; @@ -1845,10 +1843,10 @@ namespace Slang // Iterate over the members and look for one that matches // the expected signature for the requirement. - for (auto memberDecl = firstMemberOfName; memberDecl; memberDecl = memberDecl->nextInContainerWithSameName) + for (auto member : lookupResult) { - if (doesMemberSatisfyRequirement(DeclRef<Decl>(memberDecl, typeDeclRef.substitutions), requiredMemberDeclRef, requirementWitness)) - return memberDecl; + if (doesMemberSatisfyRequirement(member.declRef, requiredMemberDeclRef, requirementWitness)) + return member.declRef.getDecl(); } // No suitable member found, although there were candidates. @@ -1867,7 +1865,7 @@ namespace Slang // (via the given `inheritanceDecl`) actually provides // members to satisfy all the requirements in the interface. bool checkInterfaceConformance( - DeclRef<AggTypeDecl> typeDeclRef, + DeclRef<AggTypeDeclBase> typeDeclRef, InheritanceDecl* inheritanceDecl, DeclRef<InterfaceDecl> interfaceDeclRef) { @@ -1925,7 +1923,7 @@ namespace Slang } bool checkConformanceToType( - DeclRef<AggTypeDecl> typeDeclRef, + DeclRef<AggTypeDeclBase> typeDeclRef, InheritanceDecl* inheritanceDecl, Type* baseType) { @@ -1953,7 +1951,7 @@ namespace Slang // `inheritanceDecl` actually does what it needs to // for that inheritance to be valid. bool checkConformance( - DeclRef<AggTypeDecl> typeDecl, + DeclRef<AggTypeDeclBase> typeDecl, InheritanceDecl* inheritanceDecl) { // Look at the type being inherited from, and validate @@ -1963,10 +1961,10 @@ namespace Slang } bool checkConformance( - AggTypeDecl* typeDecl, + AggTypeDeclBase* typeDecl, InheritanceDecl* inheritanceDecl) { - return checkConformance(DeclRef<AggTypeDecl>(typeDecl, SubstitutionSet()), inheritanceDecl); + return checkConformance(DeclRef<AggTypeDeclBase>(typeDecl, SubstitutionSet()), inheritanceDecl); } void visitAggTypeDecl(AggTypeDecl* decl) @@ -3479,10 +3477,11 @@ namespace Slang // TODO: need to check that the target type names a declaration... + DeclRef<AggTypeDecl> aggTypeDeclRef; if (auto targetDeclRefType = decl->targetType->As<DeclRefType>()) { // Attach our extension to that type as a candidate... - if (auto aggTypeDeclRef = targetDeclRefType->declRef.As<AggTypeDecl>()) + if (aggTypeDeclRef = targetDeclRefType->declRef.As<AggTypeDecl>()) { auto aggTypeDecl = aggTypeDeclRef.getDecl(); decl->nextCandidateExtension = aggTypeDecl->candidateExtensions; @@ -3516,6 +3515,14 @@ namespace Slang EnsureDecl(m); } + if (aggTypeDeclRef) + { + for (auto inheritanceDecl : decl->getMembersOfType<InheritanceDecl>()) + { + checkConformance(aggTypeDeclRef.getDecl(), inheritanceDecl); + } + } + decl->SetCheckState(DeclCheckState::Checked); } @@ -3802,7 +3809,7 @@ namespace Slang if( auto aggTypeDeclRef = declRef.As<AggTypeDecl>() ) { - for( auto inheritanceDeclRef : getMembersOfType<InheritanceDecl>(aggTypeDeclRef)) + for( auto inheritanceDeclRef : getMembersOfTypeWithExt<InheritanceDecl>(aggTypeDeclRef)) { EnsureDecl(inheritanceDeclRef.getDecl()); |
