Skip to content

Commit ed62e24

Browse files
author
Harlan Haskins
committed
[Sema] Stop filtering nested protocol types from lookup
This check wasn't ever correct, because the fact that the the protocol comes from another module doesn't change the fact that the type is valid for lookup within this module. It incorrectly rejects the following, valid code: ```swift // In A.swift public protocol A {} ``` ``` // In B.swift import A extension A { typealias B = Int func b(_ b: Self.B) {} } ```
1 parent 98f563d commit ed62e24

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,16 +2046,8 @@ TypeDecl *EquivalenceClass::lookupNestedType(
20462046
continue;
20472047
}
20482048

2049-
// If this is another type declaration, determine whether we should
2050-
// record it.
2049+
// If this is another type declaration, record it.
20512050
if (auto type = dyn_cast<TypeDecl>(member)) {
2052-
// FIXME: Filter out type declarations that aren't in the same
2053-
// module as the protocol itself. This is an unprincipled hack, but
2054-
// provides consistent lookup semantics for the generic signature
2055-
// builder in all contents.
2056-
if (type->getDeclContext()->getParentModule()
2057-
!= proto->getParentModule())
2058-
continue;
20592051

20602052
// Resolve the signature of this type.
20612053
if (!type->hasInterfaceType()) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public protocol AnExternalProtocol {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -emit-module-path %t/ExternalProtocol.swiftmodule %S/Inputs/external-protocol.swift -module-name ExternalProtocol
4+
// RUN: %target-swift-frontend -typecheck -I %t %s
5+
6+
import ExternalProtocol
7+
8+
extension AnExternalProtocol {
9+
typealias TypeAlias = Int
10+
11+
func methodUsingAlias(_ alias: Self.TypeAlias) {}
12+
}

0 commit comments

Comments
 (0)