Skip to content
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
9 changes: 6 additions & 3 deletions lib/Sema/ResilienceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,17 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
TAD->getName(), definingModule->getNameStr(), D->getNameStr(),
static_cast<unsigned>(*reason), definingModule->getName(),
static_cast<unsigned>(originKind))
.warnUntilSwiftVersion(6);
.warnUntilSwiftVersionIf(originKind != DisallowedOriginKind::SPIOnly,
6);
} else {
ctx.Diags
.diagnose(loc,
diag::inlinable_typealias_desugars_to_type_from_hidden_module,
TAD->getName(), definingModule->getNameStr(), D->getNameStr(),
fragileKind.getSelector(), definingModule->getName(),
static_cast<unsigned>(originKind))
.warnUntilSwiftVersion(6);
.warnUntilSwiftVersionIf(originKind != DisallowedOriginKind::SPIOnly,
6);
}
D->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);

Expand Down Expand Up @@ -253,7 +255,8 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
M->getName(),
static_cast<unsigned>(originKind))
.warnUntilSwiftVersionIf((useConformanceAvailabilityErrorsOption &&
!ctx.LangOpts.EnableConformanceAvailabilityErrors) ||
!ctx.LangOpts.EnableConformanceAvailabilityErrors &&
originKind != DisallowedOriginKind::SPIOnly) ||
originKind == DisallowedOriginKind::ImplicitlyImported,
6);

Expand Down
1 change: 1 addition & 0 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
auto importer = ID->getModuleContext();
if (target &&
!ID->getAttrs().hasAttribute<ImplementationOnlyAttr>() &&
!ID->getAttrs().hasAttribute<SPIOnlyAttr>() &&
target->getLibraryLevel() == LibraryLevel::SPI) {

auto &diags = ID->getASTContext().Diags;
Expand Down
3 changes: 3 additions & 0 deletions test/SPI/spi-only-import-exportability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public func publicInlinableUser() {

let p: PublicType = PublicType()
p.spiOnlyExtensionMethod() // expected-error {{instance method 'spiOnlyExtensionMethod()' cannot be used in an '@inlinable' function because 'SPIOnlyImportedLib' was imported for SPI only}}
conformanceUse(p) // expected-error{{cannot use conformance of 'PublicType' to 'PublicProtocol' here; 'SPIOnlyImportedLib' was imported for SPI only}}
}
#endif

Expand All @@ -131,6 +132,7 @@ public func spiInlinableUser() {

let p: PublicType = PublicType()
p.spiOnlyExtensionMethod()
conformanceUse(p)
}

public func implementationDetailsUser() {
Expand All @@ -142,6 +144,7 @@ public func implementationDetailsUser() {

let p: PublicType = PublicType()
p.spiOnlyExtensionMethod()
conformanceUse(p)
}

public struct ClientStruct {
Expand Down
12 changes: 12 additions & 0 deletions test/Sema/implementation-only-import-suggestion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ import LocalClang // expected-error{{private module 'LocalClang' is imported pub
@_implementationOnly import FullyPrivateClang
@_implementationOnly import LocalClang

/// Expect no errors with spi-only imports.
// RUN: %target-swift-frontend -typecheck -sdk %t/sdk -module-cache-path %t %s \
// RUN: -experimental-spi-only-imports \
// RUN: -F %t/sdk/System/Library/PrivateFrameworks/ \
// RUN: -library-level api -D SPI_ONLY_IMPORTS
#elseif SPI_ONLY_IMPORTS

@_spiOnly import PrivateSwift
@_spiOnly import PublicClang_Private
@_spiOnly import FullyPrivateClang
@_spiOnly import LocalClang

#endif

/// Test error message on an unknown library level name.
Expand Down
15 changes: 15 additions & 0 deletions test/Sema/implicit-import-typealias.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesNoImport.swift -I %t
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesImplementationOnlyImport.swift -I %t
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesSPIOnlyImport.swift -I %t -experimental-spi-only-imports
// RUN: %target-swift-frontend -typecheck -verify %t/UsesAliasesWithImport.swift -I %t

/// The swiftinterface is broken by the missing import without the workaround.
Expand Down Expand Up @@ -101,6 +102,20 @@ import Aliases
public func takesGeneric<T: ProtoAlias>(_ t: T) {}


//--- UsesAliasesSPIOnlyImport.swift

import Aliases
@_spiOnly import Original

@inlinable public func inlinableFunc() {
// expected-error@+1 {{'StructAlias' aliases 'Original.Struct' and cannot be used in an '@inlinable' function because 'Original' was imported for SPI only}}
_ = StructAlias.self
}

// expected-error@+1 {{'ProtoAlias' aliases 'Original.Proto' and cannot be used here because 'Original' was imported for SPI only}}
public func takesGeneric<T: ProtoAlias>(_ t: T) {}


//--- UsesAliasesWithImport.swift

import Aliases
Expand Down