From f8bf75cf1ae0aeee155996a917c2925bc500f3e2 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 25 Oct 2023 07:45:23 -0700 Subject: Support generic interfaces. (#3278) * Initial support for generic interfaces. * Cleanup. * Add generic syntax for interfaces. --------- Co-authored-by: Yong He --- source/slang/slang-ast-decl-ref.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source/slang/slang-ast-decl-ref.cpp') diff --git a/source/slang/slang-ast-decl-ref.cpp b/source/slang/slang-ast-decl-ref.cpp index c77cf72ed..c9511e4e7 100644 --- a/source/slang/slang-ast-decl-ref.cpp +++ b/source/slang/slang-ast-decl-ref.cpp @@ -150,6 +150,11 @@ Val* LookupDeclRef::_resolveImplOverride() DeclRefBase* LookupDeclRef::_getBaseOverride() { + auto supType = getWitness()->getSup(); + if (auto declRefType = as(supType)) + { + return declRefType->getDeclRef(); + } return nullptr; } @@ -432,10 +437,13 @@ DeclRef createDefaultSubstitutionsIfNeeded( ShortList genericParentDecls; auto lastSubstNode = SubstitutionSet(declRef).getInnerMostNodeWithSubstInfo(); auto lastGenApp = as(lastSubstNode); + auto lastLookup = as(lastSubstNode); for (auto dd = declRef.getDecl()->parentDecl; dd; dd = dd->parentDecl) { if (lastGenApp && dd == lastGenApp->getGenericDecl()) break; + if (lastLookup && lastLookup->getDecl()->isChildOf(dd)) + break; if (auto gen = as(dd)) genericParentDecls.add(gen); } @@ -454,6 +462,8 @@ DeclRef createDefaultSubstitutionsIfNeeded( } parentDeclRef = astBuilder->getGenericAppDeclRef(parentDeclRef.as(), args.getArrayView()); } + if (!parentDeclRef) + return declRef; if (parentDeclRef.getDecl() == declRef.getDecl()) return parentDeclRef; return astBuilder->getMemberDeclRef(parentDeclRef, declRef.getDecl()); -- cgit v1.2.3