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 include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -3831,7 +3831,8 @@ ERROR(decl_from_hidden_module,none,
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances|"
"in a public or '@usableFromInline' conformance|"
"in an '@available' attribute here}1; "
"in an '@available' attribute here|"
"in a property declaration marked public or in a '@frozen' or '@usableFromInline' context}1; "
"%select{%2 has been imported as implementation-only|"
"it is an SPI imported from %2|"
"it is SPI|"
Expand All @@ -3848,7 +3849,8 @@ ERROR(typealias_desugars_to_type_from_hidden_module,none,
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformance|"
"in a public or '@usableFromInline' conformance|"
"<<ERROR>>}3 "
"<<ERROR>>|"
"in a property declaration marked public or in a '@frozen' or '@usableFromInline' context}3 "
"because %select{%4 has been imported as implementation-only|"
"it is an SPI imported from %4|"
"<<ERROR>>|"
Expand All @@ -3863,7 +3865,8 @@ ERROR(conformance_from_implementation_only_module,none,
"as result builder here|"
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances|"
"<<ERROR>>|<<ERROR>>}2; "
"<<ERROR>>|<<ERROR>>|"
"in a property declaration marked public or in a '@frozen' or '@usableFromInline' context}2; "
"%select{%3 has been imported as implementation-only|"
"the conformance is declared as SPI in %3|"
"the conformance is declared as SPI|"
Expand Down
1 change: 1 addition & 0 deletions lib/Sema/ResilienceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ static bool shouldDiagnoseDeclAccess(const ValueDecl *D,
case ExportabilityReason::General:
case ExportabilityReason::ResultBuilder:
case ExportabilityReason::PropertyWrapper:
case ExportabilityReason::PublicVarDecl:
return false;
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2376,7 +2376,8 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
if (seenVars.count(theVar))
return;

checkType(theVar->getValueInterfaceType(), /*typeRepr*/nullptr, theVar);
checkType(theVar->getValueInterfaceType(), /*typeRepr*/nullptr, theVar,
ExportabilityReason::PublicVarDecl);

for (auto attr : theVar->getAttachedPropertyWrappers()) {
checkType(attr->getType(), attr->getTypeRepr(), theVar,
Expand All @@ -2398,7 +2399,8 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
});

checkType(TP->hasType() ? TP->getType() : Type(),
TP->getTypeRepr(), anyVar ? (Decl *)anyVar : (Decl *)PBD);
TP->getTypeRepr(), anyVar ? (Decl *)anyVar : (Decl *)PBD,
ExportabilityReason::PublicVarDecl);

// Check the property wrapper types.
if (anyVar) {
Expand Down
4 changes: 3 additions & 1 deletion lib/Sema/TypeCheckAvailability.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ enum class DeclAvailabilityFlag : uint8_t {
using DeclAvailabilityFlags = OptionSet<DeclAvailabilityFlag>;

// This enum must be kept in sync with
// diag::decl_from_hidden_module and
// diag::decl_from_hidden_module,
// diag::typealias_desugars_to_type_from_hidden_module, and
// diag::conformance_from_implementation_only_module.
enum class ExportabilityReason : unsigned {
General,
Expand All @@ -79,6 +80,7 @@ enum class ExportabilityReason : unsigned {
ExtensionWithConditionalConformances,
Inheritance,
AvailableAttribute,
PublicVarDecl,
};

/// A description of the restrictions on what declarations can be referenced
Expand Down
2 changes: 1 addition & 1 deletion test/Availability/spi-available-context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class Bar {

@available(macOS 10.10, iOS 8.0, *)
public class Baz {
public var macos: MacOSSPIProto? // expected-error {{cannot use protocol 'MacOSSPIProto' here; it is SPI}}
public var macos: MacOSSPIProto? // expected-error {{cannot use protocol 'MacOSSPIProto' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
public var ios: iOSSPIProto?
}
2 changes: 1 addition & 1 deletion test/Availability/spi-available-swift-module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import Foo

@available(macOS 10.10, iOS 8.0, *)
public struct Foo {
public var macos: MacOSSPIClass // expected-error {{cannot use class 'MacOSSPIClass' here; it is an SPI imported from 'Foo'}}
public var macos: MacOSSPIClass // expected-error {{cannot use class 'MacOSSPIClass' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is an SPI imported from 'Foo'}}
public var ios: iOSSPIClass
}
6 changes: 3 additions & 3 deletions test/ClangImporter/availability_spi_as_unavailable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import SPIContainer
@_spi(a) public let a: SPIInterface1 = .init()
@_spi(a) public let b: SPIInterface2 = .init()

public let c: SPIInterface1 = .init() // expected-error{{cannot use class 'SPIInterface1' here; it is an SPI imported from 'SPIContainer'}}
public let d: SPIInterface2 = .init() // expected-error{{cannot use class 'SPIInterface2' here; it is an SPI imported from 'SPIContainer'}}
public let c: SPIInterface1 = .init() // expected-error{{cannot use class 'SPIInterface1' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is an SPI imported from 'SPIContainer'}}
public let d: SPIInterface2 = .init() // expected-error{{cannot use class 'SPIInterface2' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is an SPI imported from 'SPIContainer'}}

@inlinable
public func inlinableUsingSPI() {
Expand All @@ -21,7 +21,7 @@ public func inlinableUsingSPI() {
public let e: SPIInterface2 = .init()

@available(iOS, unavailable)
public let f: SPIInterface2 = .init() // expected-error{{cannot use class 'SPIInterface2' here; it is an SPI imported from 'SPIContainer'}}
public let f: SPIInterface2 = .init() // expected-error{{cannot use class 'SPIInterface2' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is an SPI imported from 'SPIContainer'}}

@inlinable
@available(macOS, unavailable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
@_spi(a) public let a: SPIInterface1
@_spi(a) public let b: SPIInterface2

public let c: SPIInterface1 // expected-error{{cannot use class 'SPIInterface1' here; it is an SPI imported from '__ObjC'}}
public let d: SPIInterface2 // expected-error{{cannot use class 'SPIInterface2' here; it is an SPI imported from '__ObjC'}}
public let c: SPIInterface1 // expected-error{{cannot use class 'SPIInterface1' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is an SPI imported from '__ObjC'}}
public let d: SPIInterface2 // expected-error{{cannot use class 'SPIInterface2' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is an SPI imported from '__ObjC'}}

@inlinable
public func inlinableUsingSPI() { // expected-warning{{public declarations should have an availability attribute with an introduction version}}
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/availability_spi_transitive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import SPIContainerImporter

@_spi(a) public let a: SPIInterface1

public let c: SPIInterface1 // expected-error{{cannot use class 'SPIInterface1' here; it is an SPI imported from 'SPIContainer'}}
public let c: SPIInterface1 // expected-error{{cannot use class 'SPIInterface1' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is an SPI imported from 'SPIContainer'}}
4 changes: 2 additions & 2 deletions test/SPI/implementation_only_spi_import_exposability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public protocol IOIProtocol {}

public struct PublicStruct : IOIProtocol, SPIProtocol { // expected-error {{cannot use protocol 'IOIProtocol' in a public or '@usableFromInline' conformance; 'Lib' has been imported as implementation-only}}
// expected-error @-1 {{cannot use protocol 'SPIProtocol' in a public or '@usableFromInline' conformance; 'Lib' has been imported as implementation-only}}
public var spiStruct = SPIStruct() // expected-error {{cannot use struct 'SPIStruct' here; 'Lib' has been imported as implementation-only}}
public var ioiStruct = IOIStruct() // expected-error {{cannot use struct 'IOIStruct' here; 'Lib' has been imported as implementation-only}}
public var spiStruct = SPIStruct() // expected-error {{cannot use struct 'SPIStruct' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'Lib' has been imported as implementation-only}}
public var ioiStruct = IOIStruct() // expected-error {{cannot use struct 'IOIStruct' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'Lib' has been imported as implementation-only}}

@inlinable
public func publicInlinable() {
Expand Down
8 changes: 4 additions & 4 deletions test/SPI/local_spi_decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func inlinable() -> SPIClass { // expected-error {{class 'SPIClass' cannot be us
// expected-error@-1 {{stored property 'spiInFrozen' cannot be declared '@_spi' in a '@frozen' struct}}

var spiTypeInFrozen = SPIStruct() // expected-error {{struct 'SPIStruct' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-1 {{cannot use struct 'SPIStruct' here; it is SPI}}
// expected-error@-1 {{cannot use struct 'SPIStruct' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
// expected-error@-2 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}

private var spiTypeInFrozen1: SPIClass // expected-error {{cannot use class 'SPIClass' here; it is SPI}}
private var spiTypeInFrozen1: SPIClass // expected-error {{cannot use class 'SPIClass' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
}

@_spi(S)
Expand All @@ -81,8 +81,8 @@ public func genFuncBad<T: SPIProtocol>(_ t: T) {} // expected-error {{cannot use
@_spi(S) func internalCantBeSPI() {} // expected-error{{internal global function cannot be declared '@_spi' because only public and open declarations can be '@_spi'}} {{1-10=}}

public struct PublicStructWithProperties {
public var a: SPIClass // expected-error {{cannot use class 'SPIClass' here; it is SPI}}
public var b = SPIClass() // expected-error {{cannot use class 'SPIClass' here; it is SPI}}
public var a: SPIClass // expected-error {{cannot use class 'SPIClass' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
public var b = SPIClass() // expected-error {{cannot use class 'SPIClass' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
}

@_spi(S)
Expand Down
2 changes: 1 addition & 1 deletion test/SPI/spi-only-import-exportability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public func implementationDetailsUser() {

public struct ClientStruct {
#if !SKIP_ERRORS
public var a: SPIOnlyStruct // expected-error {{cannot use struct 'SPIOnlyStruct' here; 'SPIOnlyImportedLib' was imported for SPI only}}
public var a: SPIOnlyStruct // expected-error {{cannot use struct 'SPIOnlyStruct' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'SPIOnlyImportedLib' was imported for SPI only}}
// expected-error@+1 {{cannot use property 'wrappedValue' here; 'SPIOnlyImportedLib' was imported for SPI only}}
@SPIOnlyPropertyWrapper(42) public var aWrapped: Any // expected-error {{cannot use generic struct 'SPIOnlyPropertyWrapper' as property wrapper here; 'SPIOnlyImportedLib' was imported for SPI only}}
#endif
Expand Down
30 changes: 15 additions & 15 deletions test/SPI/spi_members.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public struct ResilientStructSPIMembers {
@_spi(Foo) public var computedProperty: SPIType { SPIType() }

@_spi(Foo) public var storedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
// expected-error@-2 {{stored property 'storedProperty1' cannot be declared '@_spi' in a '@frozen' struct}}

@_spi(Foo) public var storedProperty2 = SPIType()
Expand All @@ -89,7 +89,7 @@ public struct ResilientStructSPIMembers {
// expected-error@-1 {{stored property 'lazyProperty1' cannot be declared '@_spi' in a '@frozen' struct}}

@_spi(Foo) public lazy var lazyProperty2: SPIType = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
// expected-error@-2 {{stored property 'lazyProperty2' cannot be declared '@_spi' in a '@frozen' struct}}

@_spi(Foo) @Wrapper public var wrappedProperty1: SPIType
Expand All @@ -108,24 +108,24 @@ public struct ResilientStructSPIMembers {
public func method(_: SPIType) {} // expected-error {{cannot use class 'SPIType' here; it is SPI}}

public var storedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

public var storedProperty2 = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
// expected-error@-2 {{class 'SPIType' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-3 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}

public var computedProperty: SPIType { SPIType() } // expected-error {{cannot use class 'SPIType' here; it is SPI}}
public var computedProperty: SPIType { SPIType() } // expected-error {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

public lazy var lazyProperty1 = SPIType() // expected-error {{cannot use class 'SPIType' here; it is SPI}}
public lazy var lazyProperty1 = SPIType() // expected-error {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

public lazy var lazyProperty2: SPIType = SPIType() // expected-error {{cannot use class 'SPIType' here; it is SPI}}
public lazy var lazyProperty2: SPIType = SPIType() // expected-error {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

@Wrapper public var wrappedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

@Wrapper public var wrappedProperty2 = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
// expected-error@-2 {{class 'SPIType' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-3 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}

Expand All @@ -140,24 +140,24 @@ public struct ResilientStructSPIMembers {
private func method(_: SPIType) {}

private var storedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

private var storedProperty2 = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
// expected-error@-2 {{class 'SPIType' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-3 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}

private var computedProperty: SPIType { SPIType() }

private lazy var lazyProperty1 = SPIType() // expected-error {{cannot use class 'SPIType' here; it is SPI}}
private lazy var lazyProperty1 = SPIType() // expected-error {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

private lazy var lazyProperty2: SPIType = SPIType() // expected-error {{cannot use class 'SPIType' here; it is SPI}}
private lazy var lazyProperty2: SPIType = SPIType() // expected-error {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

@Wrapper private var wrappedProperty1: SPIType
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}

@Wrapper private var wrappedProperty2 = SPIType()
// expected-error@-1 {{cannot use class 'SPIType' here; it is SPI}}
// expected-error@-1 {{cannot use class 'SPIType' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; it is SPI}}
// expected-error@-2 {{class 'SPIType' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
// expected-error@-3 {{initializer 'init()' cannot be used in a property initializer in a '@frozen' type because it is SPI}}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/access-level-import-embedded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public func legalAccessToIndirect(arg: StructFromIndirect = StructFromIndirect()

public struct ExposedLayoutPublic {
public var publicField: StructFromDirect // expected-error {{property cannot be declared public because its type uses an internal type}}
// expected-error @-1 {{cannot use struct 'StructFromDirect' here; 'directs' has been imported as implementation-only}}
// expected-error @-1 {{cannot use struct 'StructFromDirect' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'directs' has been imported as implementation-only}}
// expected-note @-2 {{struct 'StructFromDirect' is imported by this file as 'internal' from 'directs'}}

private var privateField: StructFromDirect
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/implementation-only-import-embedded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public func legalAccessToIndirect(arg: StructFromIndirect = StructFromIndirect()
}

public struct ExposedLayoutPublic {
public var publicField: StructFromDirect // expected-error {{cannot use struct 'StructFromDirect' here; 'directs' has been imported as implementation-only}}
public var publicField: StructFromDirect // expected-error {{cannot use struct 'StructFromDirect' in a property declaration marked public or in a '@frozen' or '@usableFromInline' context; 'directs' has been imported as implementation-only}}

private var privateField: StructFromDirect // FIXME should error
}
Expand Down
Loading