Skip to content

Commit eefea8f

Browse files
committed
[Scope map] Handle unqualified name lookup into protocols and protocol extensions properly.
We need to use the 'Self' type, not the nominal type itself.
1 parent 7cb1302 commit eefea8f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/AST/NameLookup.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,12 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
598598

599599
// Dig out the type we're looking into.
600600
// FIXME: We shouldn't need to compute a type to perform this lookup.
601-
auto lookupType = dc->getDeclaredTypeInContext();
601+
Type lookupType;
602+
603+
if (dc->getAsProtocolOrProtocolExtensionContext())
604+
lookupType = dc->getSelfTypeInContext();
605+
else
606+
lookupType = dc->getDeclaredTypeInContext();
602607
if (!lookupType || lookupType->is<ErrorType>()) continue;
603608

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

test/NameBinding/scope_map_lookup.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,28 @@ class LazyProperties {
5252

5353
lazy var prop5: Int = { self.value + 1 }()
5454
}
55+
56+
// Protocol extensions.
57+
// Extending via a superclass constraint.
58+
class Superclass {
59+
func foo() { }
60+
static func bar() { }
61+
62+
typealias Foo = Int
63+
}
64+
65+
protocol PConstrained4 { }
66+
67+
extension PConstrained4 where Self : Superclass {
68+
final func testFoo() -> Foo {
69+
foo()
70+
self.foo()
71+
72+
return Foo(5)
73+
}
74+
75+
final static func testBar() {
76+
bar()
77+
self.bar()
78+
}
79+
}

0 commit comments

Comments
 (0)