Skip to content

Allow SPI access within the same module in checkAccess #31591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3500,7 +3500,10 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
case AccessLevel::Public:
case AccessLevel::Open: {
if (useDC && VD->isSPI()) {
auto *useSF = dyn_cast<SourceFile>(useDC->getModuleScopeContext());
auto useModuleScopeContext = useDC->getModuleScopeContext();
if (useModuleScopeContext == sourceDC->getModuleScopeContext()) return true;

auto *useSF = dyn_cast<SourceFile>(useModuleScopeContext);
return !useSF || useSF->isImportedAsSPI(VD);
}
return true;
Expand Down
37 changes: 37 additions & 0 deletions test/SPI/equatable_and_conformances.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Test how SPI affects access control in protocol conformance lookup.

// RUN: %target-build-swift %s -swift-version 5

// rdar://61043406

@_spi(Private)
public struct SPIEquatable : Equatable {
public static func ==(lhs: SPIEquatable, rhs: SPIEquatable) -> Bool {
return true
}
}

// rdar://61987739

@_spi(Private)
public struct SPIStruct {}

public protocol PublicProto {
func thingOne()

@_spi(Private)
func thingTwo(_ data: SPIStruct)
}

extension PublicProto {
@_spi(Private)
public func thingTwo(_ data: SPIStruct) {
// default implementation
}
}

fileprivate struct FilePrivateStruct: PublicProto {
func thingOne() {
// OK
}
}