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/lower-to-ir.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/lower-to-ir.cpp')
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 61ca53278..498783f4b 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -2788,19 +2788,30 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> // TODO: if this inheritance declaration is under an extension, // then we should construct the type that is being extended, // and not a reference to the extension itself. - auto parentDecl = inheritanceDecl->ParentDecl; - RefPtr<Type> type = DeclRefType::Create( - context->getSession(), - makeDeclRef(parentDecl)); + auto parentDecl = inheritanceDecl->ParentDecl; + RefPtr<Type> type; + if (auto extParentDecl = dynamic_cast<ExtensionDecl*>(parentDecl)) + { + type = extParentDecl->targetType.type; + if (auto declRefType = type.As<DeclRefType>()) + { + if (auto aggTypeDecl = declRefType->declRef.As<AggTypeDecl>()) + parentDecl = aggTypeDecl.getDecl(); + } + } + else + { + type = DeclRefType::Create( + context->getSession(), + makeDeclRef(parentDecl)); + } // What is the super-type that we have declared we inherit from? RefPtr<Type> superType = inheritanceDecl->base.type; // Construct the mangled name for the witness table, which depends // on the type that is conforming, and the type that it conforms to. - String mangledName = getMangledNameForConformanceWitness( - makeDeclRef(parentDecl), - superType); + String mangledName = getMangledNameForConformanceWitness(type, superType); // Build an IR level witness table, which will represent the // conformance of the type to its super-type. |
