- Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathaccessibility_package_inline.swift
172 lines (148 loc) · 4.88 KB
/
accessibility_package_inline.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
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
packageprotocolPackageProto{
varpkgVar:Double{getset}
func pkgFunc()
}
// expected-note@+1 *{{class 'PackageKlass' is not '@usableFromInline' or public}}
packageclassPackageKlass{
packageinit(){} // expected-note *{{initializer 'init()' is not '@usableFromInline' or public}}
packageprivate(set)varpkgVar:Double=1.0
packagefunc pkgFunc(){}
}
@usableFromInline
packageclassPackageKlassProto:PackageProto{
@usableFromInline
packageinit(){}
@usableFromInline
packagevarpkgVar=1.0
packagefunc pkgFunc(){}
}
@usableFromInline
packageclassPackageKlassForInline{
@usableFromInline
packageinit(){}
}
protocolInternalProto{
varinternalVar:Double{getset}
func internalFunc()
}
// expected-note@+1 *{{class 'InternalKlass' is not '@usableFromInline' or public}}
classInternalKlass{
init(){} // expected-note *{{initializer 'init()' is not '@usableFromInline' or public}}
}
@usableFromInline
classInternalKlassProto:InternalProto{
@usableFromInline
init(){}
varinternalVar=1.0
func internalFunc(){}
}
@usableFromInline
classInternalKlassForInline{
@usableFromInline
init(){}
}
@inlinable
publicfunc publicFunc(){
leta=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}}
letb=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}}
letc=PackageKlassProto()
letd=InternalKlassProto()
lete=PackageKlassForInline()
letf=InternalKlassForInline()
print(a, b, c, d, e, f)
}
@inlinable
func internalFunc(){
leta=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}}
letb=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}}
letc=PackageKlassProto()
letd=InternalKlassProto()
lete=PackageKlassForInline()
letf=InternalKlassForInline()
print(a, b, c, d, e, f)
}
@inlinable
packagefunc packageFunc(){
leta=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}}
letb=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}}
letc=PackageKlassProto()
letd=InternalKlassProto()
lete=PackageKlassForInline()
letf=InternalKlassForInline()
print(a, b, c, d, e, f)
}
//--- UtilsGood.swift
packageprotocolPackageProto{
varpkgVar:Double{getset}
func pkgFunc()
}
packageclassPackageKlass{
packageinit(){}
packageprivate(set)varpkgVar:Double=1.0
packagefunc pkgFunc(){}
}
@usableFromInline
packageclassPackageKlassForInline{
@usableFromInline
packageinit(){}
}
classInternalKlass{
init(){}
}
@usableFromInline
classInternalKlassForInline{
@usableFromInline
init(){}
}
@inlinable
publicfunc publicFunc(){
letx=PackageKlassForInline()
lety=InternalKlassForInline()
print(x, y)
}
@inlinable
func internalFunc(){
letx=PackageKlassForInline()
lety=InternalKlassForInline()
print(x, y)
}
@inlinable
packagefunc packageFunc(){
letx=PackageKlassForInline()
lety=InternalKlassForInline()
print(x, y)
}
//--- LibOtherPackage.swift
import UtilsGood
@inlinable
publicfunc libFunc(){
publicFunc()
packageFunc() // expected-error {{cannot find 'packageFunc' in scope}}
}
//--- LibSamePackage.swift
import UtilsGood
@inlinable
publicfunc libFunc(){
publicFunc()
packageFunc() // OK
}