Skip to content

Commit c279be4

Browse files
authored
Merge pull request #31660 from xymus/spi-equatable-5.3
[5.3] Allow SPI access within the same module in checkAccess
2 parents 220cde2 + 6a8aa03 commit c279be4

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,10 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
35003500
case AccessLevel::Public:
35013501
case AccessLevel::Open: {
35023502
if (useDC && VD->isSPI()) {
3503-
auto *useSF = dyn_cast<SourceFile>(useDC->getModuleScopeContext());
3503+
auto useModuleScopeContext = useDC->getModuleScopeContext();
3504+
if (useModuleScopeContext == sourceDC->getModuleScopeContext()) return true;
3505+
3506+
auto *useSF = dyn_cast<SourceFile>(useModuleScopeContext);
35043507
return !useSF || useSF->isImportedAsSPI(VD);
35053508
}
35063509
return true;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Test how SPI affects access control in protocol conformance lookup.
2+
3+
// RUN: %target-build-swift %s -swift-version 5
4+
5+
// rdar://61043406
6+
7+
@_spi(Private)
8+
public struct SPIEquatable : Equatable {
9+
public static func ==(lhs: SPIEquatable, rhs: SPIEquatable) -> Bool {
10+
return true
11+
}
12+
}
13+
14+
// rdar://61987739
15+
16+
@_spi(Private)
17+
public struct SPIStruct {}
18+
19+
public protocol PublicProto {
20+
func thingOne()
21+
22+
@_spi(Private)
23+
func thingTwo(_ data: SPIStruct)
24+
}
25+
26+
extension PublicProto {
27+
@_spi(Private)
28+
public func thingTwo(_ data: SPIStruct) {
29+
// default implementation
30+
}
31+
}
32+
33+
fileprivate struct FilePrivateStruct: PublicProto {
34+
func thingOne() {
35+
// OK
36+
}
37+
}

0 commit comments

Comments
 (0)