Skip to content

Commit 151bdb8

Browse files
authored
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.
1 parent 4c2c085 commit 151bdb8

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

source/slang/slang-check-overload.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2167,15 +2167,16 @@ void SemanticsVisitor::AddTypeOverloadCandidates(Type* type, OverloadResolveCont
21672167
// from a value of the same type. There is no need in Slang for
21682168
// "copy constructors" but the core module currently has to define
21692169
// some just to make code that does, e.g., `float(1.0f)` work.)
2170-
2170+
LookupOptions options =
2171+
LookupOptions(uint8_t(LookupOptions::IgnoreInheritance) | uint8_t(LookupOptions::NoDeref));
21712172
LookupResult initializers = lookUpMember(
21722173
m_astBuilder,
21732174
this,
21742175
getName("$init"),
21752176
type,
21762177
context.sourceScope,
21772178
LookupMask::Default,
2178-
LookupOptions::NoDeref);
2179+
options);
21792180

21802181
AddOverloadCandidates(initializers, context);
21812182
}

source/slang/slang-lookup.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static void _lookupMembersInSuperTypeFacets(
436436
continue;
437437
}
438438

439-
auto extensionFacet = as<ExtensionDecl>(facet.getImpl()->getDeclRef().getDecl());
439+
440440
// If we are looking up in an interface, and the lookup request told us
441441
// to skip interfaces, we should do so here.
442442
if (auto baseInterfaceDeclRef = containerDeclRef.as<InterfaceDecl>())
@@ -448,10 +448,22 @@ static void _lookupMembersInSuperTypeFacets(
448448
// "Self"
449449
else if (
450450
int(request.options) & int(LookupOptions::IgnoreInheritance) &&
451-
(facet.getImpl()->directness != Facet::Directness::Self &&
452-
(!extensionFacet || !extensionFacet->targetType.type->equals(selfType))))
451+
(facet.getImpl()->directness != Facet::Directness::Self))
453452
{
454-
continue;
453+
if (auto extensionDeclRef = facet.getImpl()->getDeclRef().as<ExtensionDecl>())
454+
{
455+
if (auto targetType = getTargetType(astBuilder, extensionDeclRef))
456+
{
457+
if (!targetType->equals(selfType))
458+
{
459+
// If the extension is to the same type as the one we are looking up in, we
460+
// should include it in the lookup.
461+
continue;
462+
}
463+
}
464+
}
465+
else
466+
continue;
455467
}
456468

457469
// Some things that are syntactically `InheritanceDecl`s don't actually

0 commit comments

Comments
 (0)