File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -1476,7 +1476,12 @@ ImportKind ImportDecl::getBestImportKind(const ValueDecl *VD) {
14761476
14771477 case DeclKind::TypeAlias: {
14781478 Type type = cast<TypeAliasDecl>(VD)->getDeclaredInterfaceType ();
1479- auto *nominal = type->getAnyNominal ();
1479+ // FIXME: It's necessary to check for existentials because `getAnyNominal`
1480+ // looks through them.
1481+ auto canonical = type->getCanonicalType ();
1482+ if (isa<ExistentialType>(canonical))
1483+ return ImportKind::Type;
1484+ auto *nominal = canonical->getAnyNominal ();
14801485 if (!nominal)
14811486 return ImportKind::Type;
14821487 return getBestImportKind (nominal);
Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ NominalTypeDecl *CanType::getAnyNominal() const {
8686}
8787
8888GenericTypeDecl *CanType::getAnyGeneric () const {
89+ // FIXME: Remove checking for existential types. `getAnyGeneric` should return
90+ // the GenericTypeDecl the type is directly bound to.
8991 if (auto existential = dyn_cast<ExistentialType>(*this ))
9092 return existential->getConstraintType ()->getAnyGeneric ();
9193 if (auto ppt = dyn_cast<ParameterizedProtocolType>(*this ))
Original file line number Diff line number Diff line change @@ -7,3 +7,20 @@ public enum Choice {
77public typealias Callback = ( ) -> Void
88
99public typealias Pair < T> = ( T , T )
10+
11+ public struct NamespaceStruct {
12+
13+ public protocol NestedProtocol { }
14+
15+ public typealias AnyNestedProtocol = any NestedProtocol
16+ }
17+
18+ public typealias AnyNestedProtocol = NamespaceStruct . AnyNestedProtocol
19+
20+ public typealias NestedProtocol = NamespaceStruct . NestedProtocol
21+
22+ public protocol TopLevelProtocol {
23+
24+ }
25+
26+ public typealias AnyTopLevelProtocol = any TopLevelProtocol
Original file line number Diff line number Diff line change @@ -69,3 +69,10 @@ import typealias ambiguous.SomeStruct // expected-error{{ambiguous name 'SomeStr
6969import class ambiguous. SomeStruct // expected-error{{ambiguous name 'SomeStruct' in module 'ambiguous'}}
7070
7171import func ambiguous. overloadedFunc // no-warning
72+
73+ import protocol DeclsUsedWrongly. TopLevelProtocol // no-warning
74+ import protocol DeclsUsedWrongly. AnyTopLevelProtocol // expected-error {{type alias 'AnyTopLevelProtocol' (aka 'any TopLevelProtocol') cannot be imported as 'protocol'}} {{8-16=typealias}}
75+ import typealias DeclsUsedWrongly. AnyTopLevelProtocol // no-warning
76+ import protocol DeclsUsedWrongly. NestedProtocol // no-warning
77+ import typealias DeclsUsedWrongly. AnyNestedProtocol // no-warning
78+ import protocol DeclsUsedWrongly. AnyNestedProtocol // expected-error {{type alias 'AnyNestedProtocol' (aka 'any NamespaceStruct.NestedProtocol') cannot be imported as 'protocol'}} {{8-16=typealias}}
You can’t perform that action at this time.
0 commit comments