From a8471a1d9a5591202bf4a552aa7d1bf11088fdce Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 31 Dec 2024 09:52:51 -0800 Subject: Fix `getInheritanceInfo` for `ExtractExistentialType`. (#5971) --- source/slang/slang-check-inheritance.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'source/slang/slang-check-inheritance.cpp') diff --git a/source/slang/slang-check-inheritance.cpp b/source/slang/slang-check-inheritance.cpp index 4b0ec0f55..f774aae38 100644 --- a/source/slang/slang-check-inheritance.cpp +++ b/source/slang/slang-check-inheritance.cpp @@ -76,7 +76,7 @@ bool SharedSemanticsContext::_checkForCircularityInExtensionTargetType( InheritanceInfo SharedSemanticsContext::_getInheritanceInfo( DeclRef declRef, - DeclRefType* declRefType, + Type* selfType, InheritanceCircularityInfo* circularityInfo) { // Just as with `Type`s, we cache and re-use the inheritance @@ -95,7 +95,7 @@ InheritanceInfo SharedSemanticsContext::_getInheritanceInfo( // m_mapDeclRefToInheritanceInfo[declRef] = InheritanceInfo(); - auto info = _calcInheritanceInfo(declRef, declRefType, circularityInfo); + auto info = _calcInheritanceInfo(declRef, selfType, circularityInfo); m_mapDeclRefToInheritanceInfo[declRef] = info; getSession()->m_typeDictionarySize = Math::Max( @@ -154,7 +154,7 @@ DeclRef SharedSemanticsContext::getDependentGenericParent(DeclRef declRef, - DeclRefType* declRefType, + Type* selfType, InheritanceCircularityInfo* circularityInfo) { // This method is the main engine for computing linearized inheritance @@ -200,14 +200,6 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo( // FacetList::Builder allFacets; - // It is possible that `declRef` is itself a type declaration, - // in which case `declRefType` will be the coresponding type. - // However, if `declRef` is an `extension` declaration, we - // will extract the type that the extension applies to, so - // that we can have a consistent "self type" to represent - // the type that is at the root of the inheritance list. - // - Type* selfType = declRefType; Facet::Kind selfFacetKind = Facet::Kind::Type; auto astBuilder = _getASTBuilder(); @@ -1043,6 +1035,13 @@ InheritanceInfo SharedSemanticsContext::_calcInheritanceInfo( // return _getInheritanceInfo(declRefType->getDeclRef(), declRefType, circularityInfo); } + else if (auto extractExistentialType = as(type)) + { + return _getInheritanceInfo( + extractExistentialType->getThisTypeDeclRef(), + extractExistentialType, + circularityInfo); + } else if (auto conjunctionType = as(type)) { // In this case, we have a type of the form `L & R`, -- cgit v1.2.3