Skip to content

Commit 5bd23c1

Browse files
author
Harlan Haskins
committed
Relax @retroactive check to allow same-package declarations
1 parent b376408 commit 5bd23c1

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
@@ -184,16 +184,22 @@ usesDefaultDefinition(AssociatedTypeDecl *requirement) const {
184184
bool ProtocolConformance::isRetroactive() const {
185185
auto extensionModule = getDeclContext()->getParentModule();
186186
auto protocolModule = getProtocol()->getParentModule();
187-
if (extensionModule->isSameModuleLookingThroughOverlays(protocolModule)) {
187+
188+
auto isSameRetroactiveContext =
189+
[](ModuleDecl *moduleA, ModuleDecl *moduleB) -> bool {
190+
return moduleA->isSameModuleLookingThroughOverlays(moduleB)) ||
191+
moduleA->inSamePackage(moduleB));
192+
};
193+
194+
if (isSameRetroactiveContext(extensionModule, protocolModule)) {
188195
return false;
189196
}
190197

191198
auto conformingTypeDecl =
192199
ConformingType->getNominalOrBoundGenericNominal();
193200
if (conformingTypeDecl) {
194201
auto conformingTypeModule = conformingTypeDecl->getParentModule();
195-
if (extensionModule->
196-
isSameModuleLookingThroughOverlays(conformingTypeModule)) {
202+
if (isSameRetroactiveContext(extensionModule, conformingTypeModule)) {
197203
return false;
198204
}
199205
}
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)