summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-01-21 15:26:36 -0600
committerGitHub <noreply@github.com>2025-01-21 13:26:36 -0800
commit151bdb837f514caf5cde873aa39571525ba2e80f (patch)
tree3efdb69d5253022bd3244cb11952bc669fe5d361 /source
parent4c2c0856c21cbcc20a9c88cd2f403e2197229dbb (diff)
Fix bug: IgnoreInheritance in lookup (#6146)
* Fix bug: IgnoreInheritance in lookup When specifying IgnoreInheritance in lookup, it will ignore all members in the self extension for generic, the reason is that it doesn't specialize the target type of the extension decl when comparing with self type, so it will result that every type is unequal to the target type.
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-overload.cpp5
-rw-r--r--source/slang/slang-lookup.cpp20
2 files changed, 19 insertions, 6 deletions
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index 1ab3aa5b0..bca2f7587 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -2167,7 +2167,8 @@ void SemanticsVisitor::AddTypeOverloadCandidates(Type* type, OverloadResolveCont
// from a value of the same type. There is no need in Slang for
// "copy constructors" but the core module currently has to define
// some just to make code that does, e.g., `float(1.0f)` work.)
-
+ LookupOptions options =
+ LookupOptions(uint8_t(LookupOptions::IgnoreInheritance) | uint8_t(LookupOptions::NoDeref));
LookupResult initializers = lookUpMember(
m_astBuilder,
this,
@@ -2175,7 +2176,7 @@ void SemanticsVisitor::AddTypeOverloadCandidates(Type* type, OverloadResolveCont
type,
context.sourceScope,
LookupMask::Default,
- LookupOptions::NoDeref);
+ options);
AddOverloadCandidates(initializers, context);
}
diff --git a/source/slang/slang-lookup.cpp b/source/slang/slang-lookup.cpp
index 3667e2cd2..72fbed581 100644
--- a/source/slang/slang-lookup.cpp
+++ b/source/slang/slang-lookup.cpp
@@ -436,7 +436,7 @@ static void _lookupMembersInSuperTypeFacets(
continue;
}
- auto extensionFacet = as<ExtensionDecl>(facet.getImpl()->getDeclRef().getDecl());
+
// If we are looking up in an interface, and the lookup request told us
// to skip interfaces, we should do so here.
if (auto baseInterfaceDeclRef = containerDeclRef.as<InterfaceDecl>())
@@ -448,10 +448,22 @@ static void _lookupMembersInSuperTypeFacets(
// "Self"
else if (
int(request.options) & int(LookupOptions::IgnoreInheritance) &&
- (facet.getImpl()->directness != Facet::Directness::Self &&
- (!extensionFacet || !extensionFacet->targetType.type->equals(selfType))))
+ (facet.getImpl()->directness != Facet::Directness::Self))
{
- continue;
+ if (auto extensionDeclRef = facet.getImpl()->getDeclRef().as<ExtensionDecl>())
+ {
+ if (auto targetType = getTargetType(astBuilder, extensionDeclRef))
+ {
+ if (!targetType->equals(selfType))
+ {
+ // If the extension is to the same type as the one we are looking up in, we
+ // should include it in the lookup.
+ continue;
+ }
+ }
+ }
+ else
+ continue;
}
// Some things that are syntactically `InheritanceDecl`s don't actually