Skip to content

Commit e089345

Browse files
committed
[Scope map] Hack around AST issue involving ill-formed associated types.
DeclContext::getSelfTypeInContext() returns null types in some cases of broken protocols. Hack around this in the ASTScope-based unqualified name lookup code for now, with a narrower hack than what the existing unqualified name lookup is doing (which is even *less* principled).
1 parent c6bd5c7 commit e089345

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/AST/NameLookup.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
601601
// Dig out the type we're looking into.
602602
// FIXME: We shouldn't need to compute a type to perform this lookup.
603603
Type lookupType = dc->getSelfTypeInContext();
604+
605+
// FIXME: Hack to deal with missing 'Self' archetypes.
606+
if (!lookupType) {
607+
if (auto proto = dc->getAsProtocolOrProtocolExtensionContext())
608+
lookupType = proto->getDeclaredType();
609+
}
610+
604611
if (!lookupType || lookupType->is<ErrorType>()) continue;
605612

606613
// If we're performing a static lookup, use the metatype.

test/NameBinding/scope_map_lookup.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ protocol P1 {
2222
associatedtype A = Self
2323
}
2424

25+
// Protocols involving associated types.
26+
protocol AProtocol {
27+
associatedtype e : e // expected-error {{inheritance from non-protocol, non-class type 'Self.e'}}
28+
}
29+
2530
// Extensions.
2631
protocol P2 {
2732
}

0 commit comments

Comments
 (0)