1
1
// RUN: %empty-directory(%t)
2
- // RUN: %{python} %utils/split_file.py -o %t %s
2
+ // RUN: split-file %s %t
3
3
4
- // RUN: %target-swift-frontend -module-name UtilsGood %t/UtilsGood.swift -emit-module -emit-module-path %t/UtilsGood.swiftmodule -package-name myLib
4
+ // RUN: %target-swift-frontend -verify - module-name UtilsGood %t/UtilsGood.swift -emit-module -emit-module-path %t/UtilsGood.swiftmodule -package-name myLib
5
5
// RUN: test -f %t/UtilsGood.swiftmodule
6
6
7
- // RUN: not %target-swift-frontend -typecheck %t/Utils.swift -package-name myLib -I %t 2> %t/resultUtils.output
8
- // RUN: %FileCheck %s -input-file %t/resultUtils.output -check-prefix CHECK-UTILS
9
- // CHECK-UTILS: error: class 'PackageKlass' is package and cannot be referenced from an '@inlinable' function
10
- // CHECK-UTILS: let a = PackageKlass()
11
- // CHECK-UTILS: ^
12
- // CHECK-UTILS: note: class 'PackageKlass' is not '@usableFromInline' or public
13
- // CHECK-UTILS: package class PackageKlass {
14
- // CHECK-UTILS: ^
15
- // CHECK-UTILS: error: initializer 'init()' is package and cannot be referenced from an '@inlinable' function
16
- // CHECK-UTILS: let a = PackageKlass() // should error
17
- // CHECK-UTILS: ^
18
- // CHECK-UTILS: note: initializer 'init()' is not '@usableFromInline' or public
19
- // CHECK-UTILS: package init() {}
20
- // CHECK-UTILS: ^
21
- // CHECK-UTILS: error: class 'InternalKlass' is internal and cannot be referenced from an '@inlinable' function
22
- // CHECK-UTILS: let b = InternalKlass() // should error
23
- // CHECK-UTILS: ^
24
- // CHECK-UTILS: note: class 'InternalKlass' is not '@usableFromInline' or public
25
- // CHECK-UTILS: class InternalKlass {
26
- // CHECK-UTILS: ^
27
- // CHECK-UTILS: error: initializer 'init()' is internal and cannot be referenced from an '@inlinable' function
28
- // CHECK-UTILS: let b = InternalKlass() // should error
29
- // CHECK-UTILS: ^
30
- // CHECK-UTILS: note: initializer 'init()' is not '@usableFromInline' or public
31
- // CHECK-UTILS: init() {}
32
- // CHECK-UTILS: ^
33
-
34
- // RUN: not %target-swift-frontend -typecheck %t/Lib.swift -package-name "otherLib" -I %t 2> %t/resultLib.output
35
- // %FileCheck %s -input-file %t/resultLib.output -check-prefix CHECK-LIB
36
- // CHECK-LIB: error: cannot find 'packageFunc' in scope
37
- // CHECK-LIB: packageFunc()
38
- // CHECK-LIB: ^~~~~~~~~~~
39
-
40
- // RUN: %target-swift-frontend -module-name Lib %t/Lib.swift -emit-module -emit-module-path %t/Lib.swiftmodule -package-name myLib -I %t
41
- // RUN: test -f %t/Lib.swiftmodule
42
-
43
- // BEGIN Utils.swift
7
+ // RUN: %target-swift-frontend -typecheck -verify %t/Utils.swift -package-name myLib -I %t
8
+ // RUN: %target-swift-frontend -typecheck -verify %t/LibOtherPackage.swift -package-name otherLib -I %t
9
+ // RUN: %target-swift-frontend -typecheck -verify %t/LibSamePackage.swift -package-name myLib -I %t
10
+
11
+ //--- Utils.swift
44
12
package protocol PackageProto {
45
13
var pkgVar : Double { get set }
46
14
func pkgFunc( )
47
15
}
48
16
17
+ // expected-note@+1 *{{class 'PackageKlass' is not '@usableFromInline' or public}}
49
18
package class PackageKlass {
50
- package init ( ) { }
19
+ package init ( ) { } // expected-note *{{initializer 'init()' is not '@usableFromInline' or public}}
51
20
package private( set) var pkgVar : Double = 1.0
52
21
package func pkgFunc( ) { }
53
22
}
@@ -71,8 +40,10 @@ protocol InternalProto {
71
40
var internalVar : Double { get set }
72
41
func internalFunc( )
73
42
}
43
+
44
+ // expected-note@+1 *{{class 'InternalKlass' is not '@usableFromInline' or public}}
74
45
class InternalKlass {
75
- init ( ) { }
46
+ init ( ) { } // expected-note *{{initializer 'init()' is not '@usableFromInline' or public}}
76
47
}
77
48
@usableFromInline
78
49
class InternalKlassProto : InternalProto {
@@ -90,8 +61,12 @@ class InternalKlassForInline {
90
61
91
62
@inlinable
92
63
public func publicFunc( ) {
93
- let a = PackageKlass ( ) // should error
64
+ let a = PackageKlass ( )
65
+ // expected-error@-1 {{class 'PackageKlass' is package and cannot be referenced from an '@inlinable' function}}
66
+ // expected-error@-2 {{initializer 'init()' is package and cannot be referenced from an '@inlinable' function}}
94
67
let b = InternalKlass ( ) // should error
68
+ // expected-error@-1 {{class 'InternalKlass' is internal and cannot be referenced from an '@inlinable' function}}
69
+ // expected-error@-2 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
95
70
let c = PackageKlassProto ( )
96
71
let d = InternalKlassProto ( )
97
72
let e = PackageKlassForInline ( )
@@ -101,8 +76,12 @@ public func publicFunc() {
101
76
102
77
@inlinable
103
78
func internalFunc( ) {
104
- let a = PackageKlass ( ) // should error
105
- let b = InternalKlass ( ) // should error
79
+ let a = PackageKlass ( )
80
+ // expected-error@-1 {{class 'PackageKlass' is package and cannot be referenced from an '@inlinable' function}}
81
+ // expected-error@-2 {{initializer 'init()' is package and cannot be referenced from an '@inlinable' function}}
82
+ let b = InternalKlass ( )
83
+ // expected-error@-1 {{class 'InternalKlass' is internal and cannot be referenced from an '@inlinable' function}}
84
+ // expected-error@-2 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
106
85
let c = PackageKlassProto ( )
107
86
let d = InternalKlassProto ( )
108
87
let e = PackageKlassForInline ( )
@@ -112,16 +91,20 @@ func internalFunc() {
112
91
113
92
@inlinable
114
93
package func packageFunc( ) {
115
- let a = PackageKlass ( ) // should error
116
- let b = InternalKlass ( ) // should error
94
+ let a = PackageKlass ( )
95
+ // expected-error@-1 {{class 'PackageKlass' is package and cannot be referenced from an '@inlinable' function}}
96
+ // expected-error@-2 {{initializer 'init()' is package and cannot be referenced from an '@inlinable' function}}
97
+ let b = InternalKlass ( )
98
+ // expected-error@-1 {{class 'InternalKlass' is internal and cannot be referenced from an '@inlinable' function}}
99
+ // expected-error@-2 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
117
100
let c = PackageKlassProto ( )
118
101
let d = InternalKlassProto ( )
119
102
let e = PackageKlassForInline ( )
120
103
let f = InternalKlassForInline ( )
121
104
print ( a, b, c, d, e, f)
122
105
}
123
106
124
- // BEGIN UtilsGood.swift
107
+ //--- UtilsGood.swift
125
108
package protocol PackageProto {
126
109
var pkgVar : Double { get set }
127
110
func pkgFunc( )
@@ -170,11 +153,20 @@ package func packageFunc() {
170
153
print ( x, y)
171
154
}
172
155
173
- // BEGIN Lib.swift
156
+ //--- LibOtherPackage.swift
157
+ import UtilsGood
158
+
159
+ @inlinable
160
+ public func libFunc( ) {
161
+ publicFunc ( )
162
+ packageFunc ( ) // expected-error {{cannot find 'packageFunc' in scope}}
163
+ }
164
+
165
+ //--- LibSamePackage.swift
174
166
import UtilsGood
175
167
176
168
@inlinable
177
169
public func libFunc( ) {
178
170
publicFunc ( )
179
- packageFunc ( ) // Allowed if in same package
171
+ packageFunc ( ) // OK
180
172
}
0 commit comments