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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -verify -module-name UtilsGood %t/UtilsGood.swift -emit-module -emit-module-path %t/UtilsGood.swiftmodule -package-name myLib
// RUN: test -f %t/UtilsGood.swiftmodule
// RUN: %target-swift-frontend -typecheck -verify %t/Utils.swift -package-name myLib -I %t
// RUN: %target-swift-frontend -typecheck -verify %t/LibOtherPackage.swift -package-name otherLib -I %t
// RUN: %target-swift-frontend -typecheck -verify %t/LibSamePackage.swift -package-name myLib -I %t
//--- Utils.swift
package protocol PackageProto {
var pkgVar: Double { get set }
func pkgFunc()
}
// expected-note@+1 *{{class 'PackageKlass' is not '@usableFromInline' or public}}
package class PackageKlass {
package init() {} // expected-note *{{initializer 'init()' is not '@usableFromInline' or public}}
package private(set) var pkgVar: Double = 1.0
package func pkgFunc() {}
}
@usableFromInline
package class PackageKlassProto: PackageProto {
@usableFromInline
package init() {}
@usableFromInline
package var pkgVar = 1.0
package func pkgFunc() {}
}
@usableFromInline
package class PackageKlassForInline {
@usableFromInline
package init() {}
}
protocol InternalProto {
var internalVar: Double { get set }
func internalFunc()
}
// expected-note@+1 *{{class 'InternalKlass' is not '@usableFromInline' or public}}
class InternalKlass {
init() {} // expected-note *{{initializer 'init()' is not '@usableFromInline' or public}}
}
@usableFromInline
class InternalKlassProto: InternalProto {
@usableFromInline
init() {}
var internalVar = 1.0
func internalFunc() {}
}
@usableFromInline
class InternalKlassForInline {
@usableFromInline
init() {}
}
@inlinable
public func publicFunc() {
let a = PackageKlass()
// expected-error@-1 {{class 'PackageKlass' is package and cannot be referenced from an '@inlinable' function}}
// expected-error@-2 {{initializer 'init()' is package and cannot be referenced from an '@inlinable' function}}
let b = InternalKlass() // should error
// expected-error@-1 {{class 'InternalKlass' is internal and cannot be referenced from an '@inlinable' function}}
// expected-error@-2 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
let c = PackageKlassProto()
let d = InternalKlassProto()
let e = PackageKlassForInline()
let f = InternalKlassForInline()
print(a, b, c, d, e, f)
}
@inlinable
func internalFunc() {
let a = PackageKlass()
// expected-error@-1 {{class 'PackageKlass' is package and cannot be referenced from an '@inlinable' function}}
// expected-error@-2 {{initializer 'init()' is package and cannot be referenced from an '@inlinable' function}}
let b = InternalKlass()
// expected-error@-1 {{class 'InternalKlass' is internal and cannot be referenced from an '@inlinable' function}}
// expected-error@-2 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
let c = PackageKlassProto()
let d = InternalKlassProto()
let e = PackageKlassForInline()
let f = InternalKlassForInline()
print(a, b, c, d, e, f)
}
@inlinable
package func packageFunc() {
let a = PackageKlass()
// expected-error@-1 {{class 'PackageKlass' is package and cannot be referenced from an '@inlinable' function}}
// expected-error@-2 {{initializer 'init()' is package and cannot be referenced from an '@inlinable' function}}
let b = InternalKlass()
// expected-error@-1 {{class 'InternalKlass' is internal and cannot be referenced from an '@inlinable' function}}
// expected-error@-2 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
let c = PackageKlassProto()
let d = InternalKlassProto()
let e = PackageKlassForInline()
let f = InternalKlassForInline()
print(a, b, c, d, e, f)
}
//--- UtilsGood.swift
package protocol PackageProto {
var pkgVar: Double { get set }
func pkgFunc()
}
package class PackageKlass {
package init() {}
package private(set) var pkgVar: Double = 1.0
package func pkgFunc() {}
}
@usableFromInline
package class PackageKlassForInline {
@usableFromInline
package init() {}
}
class InternalKlass {
init() {}
}
@usableFromInline
class InternalKlassForInline {
@usableFromInline
init() {}
}
@inlinable
public func publicFunc() {
let x = PackageKlassForInline()
let y = InternalKlassForInline()
print(x, y)
}
@inlinable
func internalFunc() {
let x = PackageKlassForInline()
let y = InternalKlassForInline()
print(x, y)
}
@inlinable
package func packageFunc() {
let x = PackageKlassForInline()
let y = InternalKlassForInline()
print(x, y)
}
//--- LibOtherPackage.swift
import UtilsGood
@inlinable
public func libFunc() {
publicFunc()
packageFunc() // expected-error {{cannot find 'packageFunc' in scope}}
}
//--- LibSamePackage.swift
import UtilsGood
@inlinable
public func libFunc() {
publicFunc()
packageFunc() // OK
}
|