Skip to content

Commit 5a3761d

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 f02bac3 commit 5a3761d

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lib/AST/GenericSignatureBuilder.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -2046,17 +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;
2059-
20602051
concreteDecls.push_back(type);
20612052
continue;
20622053
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public protocol AnExternalProtocol {}
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)