|
| 1 | +/// An `@_private` import opens access to all SPIs of the imported module. |
| 2 | +/// Exports of SPI in API are still reported. |
| 3 | + |
| 4 | +// RUN: %empty-directory(%t) |
| 5 | +// RUN: split-file %s %t |
| 6 | + |
| 7 | +/// Build the library. |
| 8 | +// RUN: %target-swift-frontend -emit-module %t/Lib_FileA.swift %t/Lib_FileB.swift \ |
| 9 | +// RUN: -module-name Lib -emit-module-path %t/Lib.swiftmodule \ |
| 10 | +// RUN: -enable-library-evolution -swift-version 5 \ |
| 11 | +// RUN: -enable-private-imports |
| 12 | + |
| 13 | +/// Typecheck a @_private client. |
| 14 | +// RUN: %target-swift-frontend -typecheck -verify -I %t %t/PrivateClient.swift |
| 15 | + |
| 16 | +/// Typecheck a regular client building against the same Lib with private imports enabled. |
| 17 | +// RUN: %target-swift-frontend -typecheck -verify -I %t %t/RegularClient.swift |
| 18 | + |
| 19 | +//--- Lib_FileA.swift |
| 20 | +@_spi(S) public func spiFuncA() {} |
| 21 | +@_spi(S) public struct SPITypeA {} |
| 22 | + |
| 23 | +//--- Lib_FileB.swift |
| 24 | +@_spi(S) public func spiFuncB() {} |
| 25 | +@_spi(S) public struct SPITypeB {} |
| 26 | + |
| 27 | +//--- PrivateClient.swift |
| 28 | +@_private(sourceFile: "Lib_FileA.swift") import Lib |
| 29 | + |
| 30 | +func useOnly(a: SPITypeA, b: SPITypeB) { |
| 31 | + spiFuncA() |
| 32 | + spiFuncB() |
| 33 | +} |
| 34 | + |
| 35 | +public func export(a: SPITypeA, b: SPITypeB) { // expected-error {{cannot use struct 'SPITypeA' here; it is an SPI imported from 'Lib'}} |
| 36 | + // expected-error @-1 {{cannot use struct 'SPITypeB' here; it is an SPI imported from 'Lib'}} |
| 37 | + spiFuncA() |
| 38 | + spiFuncB() |
| 39 | +} |
| 40 | + |
| 41 | +@inlinable |
| 42 | +public func inlinableExport(a: SPITypeA, b: SPITypeB) { // expected-error {{struct 'SPITypeA' cannot be used in an '@inlinable' function because it is an SPI imported from 'Lib'}} |
| 43 | + // expected-error @-1 {{struct 'SPITypeB' cannot be used in an '@inlinable' function because it is an SPI imported from 'Lib'}} |
| 44 | + spiFuncA() // expected-error {{global function 'spiFuncA()' cannot be used in an '@inlinable' function because it is an SPI imported from 'Lib'}} |
| 45 | + spiFuncB() // expected-error {{global function 'spiFuncB()' cannot be used in an '@inlinable' function because it is an SPI imported from 'Lib'}} |
| 46 | +} |
| 47 | + |
| 48 | +//--- RegularClient.swift |
| 49 | +import Lib |
| 50 | + |
| 51 | +func useOnly(a: SPITypeA, b: SPITypeB) { // expected-error {{cannot find type 'SPITypeA' in scope}} |
| 52 | + // expected-error @-1 {{cannot find type 'SPITypeB' in scope}} |
| 53 | + spiFuncA() // expected-error {{cannot find 'spiFuncA' in scope}} |
| 54 | + spiFuncB() // expected-error {{cannot find 'spiFuncB' in scope}} |
| 55 | +} |
| 56 | + |
| 57 | +public func export(a: SPITypeA, b: SPITypeB) { // expected-error {{cannot find type 'SPITypeA' in scope}} |
| 58 | + // expected-error @-1 {{cannot find type 'SPITypeB' in scope}} |
| 59 | + spiFuncA() // expected-error {{cannot find 'spiFuncA' in scope}} |
| 60 | + spiFuncB() // expected-error {{cannot find 'spiFuncB' in scope}} |
| 61 | +} |
| 62 | + |
| 63 | +@inlinable |
| 64 | +public func inlinableExport(a: SPITypeA, b: SPITypeB) { // expected-error {{cannot find type 'SPITypeA' in scope}} |
| 65 | + // expected-error @-1 {{cannot find type 'SPITypeB' in scope}} |
| 66 | + spiFuncA() // expected-error {{cannot find 'spiFuncA' in scope}} |
| 67 | + spiFuncB() // expected-error {{cannot find 'spiFuncB' in scope}} |
| 68 | +} |
0 commit comments