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