Skip to content

Commit c0c163d

Browse files
author
Harlan Haskins
committed
Relax @retroactive check to allow same-package declarations
1 parent 3ccbcfe commit c0c163d

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,22 @@ usesDefaultDefinition(AssociatedTypeDecl *requirement) const {
185185
bool ProtocolConformance::isRetroactive() const {
186186
auto extensionModule = getDeclContext()->getParentModule();
187187
auto protocolModule = getProtocol()->getParentModule();
188-
if (extensionModule->isSameModuleLookingThroughOverlays(protocolModule)) {
188+
189+
auto isSameRetroactiveContext =
190+
[](ModuleDecl *moduleA, ModuleDecl *moduleB) -> bool {
191+
return moduleA->isSameModuleLookingThroughOverlays(moduleB)) ||
192+
moduleA->inSamePackage(moduleB));
193+
};
194+
195+
if (isSameRetroactiveContext(extensionModule, protocolModule)) {
189196
return false;
190197
}
191198

192199
auto conformingTypeDecl =
193200
ConformingType->getNominalOrBoundGenericNominal();
194201
if (conformingTypeDecl) {
195202
auto conformingTypeModule = conformingTypeDecl->getParentModule();
196-
if (extensionModule->
197-
isSameModuleLookingThroughOverlays(conformingTypeModule)) {
203+
if (isSameRetroactiveContext(extensionModule, conformingTypeModule)) {
198204
return false;
199205
}
200206
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
// RUN: %target-swift-frontend -swift-version 5 %t/OtherLibrary.swift -package-name Library -emit-module -module-name OtherLibrary -package-name Library -o %t
4+
// RUN: %target-swift-frontend -typecheck %t/Library.swift -module-name Library -package-name Library -verify -swift-version 5 -import-underlying-module -I %t
5+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -module-name Client -package-name Library -verify -swift-version 5 -I %t
6+
7+
//--- Library.swift
8+
9+
public class LibraryClass {
10+
}
11+
12+
public protocol LibraryProtocol {
13+
}
14+
15+
//--- OtherLibrary.swift
16+
public class OtherLibraryClass {}
17+
public class OtherLibraryProtocol {}
18+
19+
//--- Client.swift
20+
21+
import Library
22+
import OtherLibrary
23+
24+
// These are all fine because all 3 of these libraries are in the same package.
25+
26+
extension LibraryClass: LibraryProtocol {}
27+
extension OtherLibraryClass: LibraryProtocol {}
28+
extension LibraryClass: OtherLibraryProtocol {}

0 commit comments

Comments
 (0)