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) {
1476
1476
1477
1477
case DeclKind::TypeAlias: {
1478
1478
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 ();
1480
1485
if (!nominal)
1481
1486
return ImportKind::Type;
1482
1487
return getBestImportKind (nominal);
Original file line number Diff line number Diff line change @@ -86,6 +86,8 @@ NominalTypeDecl *CanType::getAnyNominal() const {
86
86
}
87
87
88
88
GenericTypeDecl *CanType::getAnyGeneric () const {
89
+ // FIXME: Remove checking for existential types. `getAnyGeneric` should return
90
+ // the GenericTypeDecl the type is directly bound to.
89
91
if (auto existential = dyn_cast<ExistentialType>(*this ))
90
92
return existential->getConstraintType ()->getAnyGeneric ();
91
93
if (auto ppt = dyn_cast<ParameterizedProtocolType>(*this ))
Original file line number Diff line number Diff line change @@ -7,3 +7,20 @@ public enum Choice {
7
7
public typealias Callback = ( ) -> Void
8
8
9
9
public 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
69
69
import class ambiguous. SomeStruct // expected-error{{ambiguous name 'SomeStruct' in module 'ambiguous'}}
70
70
71
71
import 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