Files
swift-mirror/test/ClangImporter/availability_spi_as_unavailable.swift
Alexis Laferrière 2d339c1260 Sema: Custom diagnostic for var decls referencing a restricted type
Replace the `here` part of the generic exportability diagnostic for
variables with: `in a property declaration marked public or in a
'@frozen' or '@usableFromInline' context`.

The full diagnostic now looks like:
```
error: cannot use struct 'ImportedType' in a property declaration marked
public or in a '@frozen' or '@usableFromInline' context;
'HiddenDependency' has been imported as implementation-only
```

This should be improved further to support implicitly exported memory
layouts in non-library-evolution and embedded.
2025-10-21 11:30:52 -07:00

31 lines
1.6 KiB
Swift

// REQUIRES: OS=macosx
// RUN: %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks -verify -verify-ignore-unrelated -DNOT_UNDERLYING -library-level api -parse-as-library -require-explicit-availability=ignore
// RUN: %target-swift-frontend -typecheck %s -F %S/Inputs/frameworks -module-name SPIContainer -import-underlying-module -verify -verify-ignore-unrelated -library-level api -parse-as-library -require-explicit-availability=ignore
#if NOT_UNDERLYING
import SPIContainer
#endif
@_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' 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() {
SharedInterface.foo() // expected-error{{class method 'foo()' cannot be used in an '@inlinable' function because it is an SPI imported from 'SPIContainer'}}
}
@available(macOS, unavailable)
public let e: SPIInterface2 = .init()
@available(iOS, unavailable)
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)
public func inlinableUnavailableUsingSPI() {
SharedInterface.foo()
}