From d33e6b7475a87d5a62101afc81813e9c9e458a70 Mon Sep 17 00:00:00 2001 From: Yong He Date: Sun, 14 Jan 2018 16:22:11 -0500 Subject: 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. --- source/slang/lower-to-ir.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'source/slang/lower-to-ir.cpp') 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 // 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 = DeclRefType::Create( - context->getSession(), - makeDeclRef(parentDecl)); + auto parentDecl = inheritanceDecl->ParentDecl; + RefPtr type; + if (auto extParentDecl = dynamic_cast(parentDecl)) + { + type = extParentDecl->targetType.type; + if (auto declRefType = type.As()) + { + if (auto aggTypeDecl = declRefType->declRef.As()) + parentDecl = aggTypeDecl.getDecl(); + } + } + else + { + type = DeclRefType::Create( + context->getSession(), + makeDeclRef(parentDecl)); + } // What is the super-type that we have declared we inherit from? RefPtr 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. -- cgit v1.2.3