11// RUN: %empty-directory(%t)
2- // RUN: %{python} %utils/split_file.py -o %t %s
2+ // RUN: split-file %s %t
33
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
55// RUN: test -f %t/UtilsGood.swiftmodule
66
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
4412package protocol PackageProto {
4513 var pkgVar : Double { get set }
4614 func pkgFunc( )
4715}
4816
17+ // expected-note@+1 *{{class 'PackageKlass' is not '@usableFromInline' or public}}
4918package class PackageKlass {
50- package init ( ) { }
19+ package init ( ) { } // expected-note *{{initializer 'init()' is not '@usableFromInline' or public}}
5120 package private( set) var pkgVar : Double = 1.0
5221 package func pkgFunc( ) { }
5322}
@@ -71,8 +40,10 @@ protocol InternalProto {
7140 var internalVar : Double { get set }
7241 func internalFunc( )
7342}
43+
44+ // expected-note@+1 *{{class 'InternalKlass' is not '@usableFromInline' or public}}
7445class InternalKlass {
75- init ( ) { }
46+ init ( ) { } // expected-note *{{initializer 'init()' is not '@usableFromInline' or public}}
7647}
7748@usableFromInline
7849class InternalKlassProto : InternalProto {
@@ -90,8 +61,12 @@ class InternalKlassForInline {
9061
9162@inlinable
9263public 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}}
9467 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}}
9570 let c = PackageKlassProto ( )
9671 let d = InternalKlassProto ( )
9772 let e = PackageKlassForInline ( )
@@ -101,8 +76,12 @@ public func publicFunc() {
10176
10277@inlinable
10378func 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}}
10685 let c = PackageKlassProto ( )
10786 let d = InternalKlassProto ( )
10887 let e = PackageKlassForInline ( )
@@ -112,16 +91,20 @@ func internalFunc() {
11291
11392@inlinable
11493package 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}}
117100 let c = PackageKlassProto ( )
118101 let d = InternalKlassProto ( )
119102 let e = PackageKlassForInline ( )
120103 let f = InternalKlassForInline ( )
121104 print ( a, b, c, d, e, f)
122105}
123106
124- // BEGIN UtilsGood.swift
107+ //--- UtilsGood.swift
125108package protocol PackageProto {
126109 var pkgVar : Double { get set }
127110 func pkgFunc( )
@@ -170,11 +153,20 @@ package func packageFunc() {
170153 print ( x, y)
171154}
172155
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
174166import UtilsGood
175167
176168@inlinable
177169public func libFunc( ) {
178170 publicFunc ( )
179- packageFunc ( ) // Allowed if in same package
171+ packageFunc ( ) // OK
180172}
0 commit comments