Skip to content

Commit e75de93

Browse files
committed
[TypeChecker] Add types nested in protocol to lookup results
Although such functionality is not yet supported we have to mirror AST lookup and add such members into results, otherwise there is a risk of inner/outer results mismatch.
1 parent c240093 commit e75de93

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/Sema/TypeCheckNameLookup.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ namespace {
195195
addResult(found);
196196
return;
197197
}
198+
} else if (isa<NominalTypeDecl>(found)) {
199+
// Declaring nested types inside other types is currently
200+
// not supported by lookup would still return such members
201+
// so we have to account for that here as well.
202+
addResult(found);
203+
return;
198204
}
199205

200206
// FIXME: the "isa<ProtocolDecl>()" check will be wrong for

test/decl/nested/protocol.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class OuterGenericClass<T> {
1919
}
2020
}
2121

22-
protocol OuterProtocol { // expected-note{{'OuterProtocol' declared here}}
22+
protocol OuterProtocol {
2323
associatedtype Hen
2424
protocol InnerProtocol { // expected-error{{protocol 'InnerProtocol' cannot be nested inside another declaration}}
2525
associatedtype Rooster
@@ -32,7 +32,7 @@ struct ConformsToOuterProtocol : OuterProtocol {
3232
typealias Hen = Int
3333

3434
func f() { let _ = InnerProtocol.self }
35-
// expected-error@-1 {{use of unresolved identifier 'InnerProtocol'}}
35+
// expected-error@-1 {{protocol 'InnerProtocol' can only be used as a generic constraint because it has Self or associated type requirements}}
3636
}
3737

3838
protocol Racoon {

0 commit comments

Comments
 (0)