1
- // This source file contains intentional type checking errors that should be
2
- // avoided when compiling with -experimental-lazy-typecheck and emitting module
3
- // outputs since all the errors occur in regions of the AST that do not
4
- // need to be type checked in order to emit a module or module interface.
1
+
2
+ struct NoTypecheck {
3
+ static let int : Int = 0
4
+ static func fatalError( ) -> Never { Swift . fatalError ( ) }
5
+ }
6
+
7
+ protocol NoTypecheckProto { }
8
+
9
+ extension NoTypecheck : PublicProto {
10
+ func req( ) -> Int { return 0 }
11
+ }
5
12
6
13
// MARK: - Global functions
7
14
8
15
public func publicFunc( ) -> Int {
9
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
16
+ return NoTypecheck . int
10
17
}
11
18
12
19
public func publicFuncWithDefaultArg( _ x: Int = 1 ) -> Int {
13
- return doesNotExist ( ) // expected-error {{cannot find 'doesNotExist' in scope}}
20
+ return NoTypecheck . int
14
21
}
15
22
16
23
package func packageFunc( ) -> Int {
17
- return false // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
24
+ return NoTypecheck . int
18
25
}
19
26
20
- func internalFunc( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
21
- return 1
27
+ func internalFunc( ) -> NoTypecheck {
28
+ return NoTypecheck ( )
22
29
}
23
30
24
31
@inlinable func inlinableFunc( ) -> Int {
25
32
return 1
26
33
}
27
34
28
- private func privateFunc( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
29
- return 1
35
+ private func privateFunc( ) -> NoTypecheck {
36
+ return NoTypecheck ( )
30
37
}
31
38
32
39
public func constrainedGenericPublicFunction< T> ( _ t: T ) where T: PublicProto {
33
- doesNotExist ( ) // expected-error {{cannot find 'doesNotExist' in scope}}
40
+ _ = NoTypecheck ( )
34
41
}
35
42
36
43
@_specialize ( exported: true , where T == PublicProto)
37
44
public func publicSpecializedFunc< T> ( _ t: T ) -> T {
38
- return doesNotExist ( ) // expected-error {{cannot find 'doesNotExist' in scope}}
45
+ _ = NoTypecheck ( )
46
+ return t
39
47
}
40
48
41
49
@available ( SwiftStdlib 5 . 1 , * )
42
- public func publicFuncWithOpaqueReturnType( ) -> some PublicProto { // expected-note {{opaque return type declared here}}
43
- return 1 // expected-error {{return type of global function 'publicFuncWithOpaqueReturnType()' requires that 'Int' conform to 'PublicProto'}}
50
+ public func publicFuncWithOpaqueReturnType( ) -> some PublicProto {
51
+ return NoTypecheck ( )
44
52
}
45
53
46
54
@available ( SwiftStdlib 5 . 1 , * )
@@ -58,38 +66,45 @@ public func publicFuncWithOpaqueReturnType() -> some PublicProto { // expected-n
58
66
public struct PublicWrapper < T> {
59
67
public var wrappedValue : T {
60
68
get {
61
- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
69
+ NoTypecheck . fatalError ( )
62
70
}
63
71
set {
64
- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
72
+ NoTypecheck . fatalError ( )
65
73
}
66
74
}
67
75
68
76
public var projectedValue : PublicWrapper { self }
69
77
70
78
public init ( wrappedValue value: T ) {
71
- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
79
+ NoTypecheck . fatalError ( )
72
80
}
73
81
}
74
82
75
83
@propertyWrapper
76
- struct InternalWrapper < T> { } // expected-error {{property wrapper type 'InternalWrapper' does not contain a non-static property named 'wrappedValue'}}
84
+ struct InternalWrapper {
85
+ var wrappedValue : NoTypecheck
86
+ }
77
87
78
88
// MARK: - Global vars
79
89
80
90
public var publicGlobalVar : Int = 0
81
91
public var publicGlobalVarInferredType = " "
82
92
public var ( publicGlobalVarInferredTuplePatX, publicGlobalVarInferredTuplePatY) = ( 0 , 1 )
83
93
84
- var internalGlobalVar : DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
85
- var internalGlobalVarInferredType = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
94
+ var internalGlobalVar : NoTypecheck = NoTypecheck ( )
95
+ var internalGlobalVarInferredType = NoTypecheck ( )
86
96
87
97
// MARK: - Nominal types
88
98
89
99
public protocol EmptyPublicProto { }
90
100
91
101
public protocol PublicProto {
92
- func req( ) -> Int // expected-note 2 {{protocol requires function 'req()' with type '() -> Int'; add a stub for conformance}}
102
+ func req( ) -> Int
103
+ }
104
+
105
+ public protocol PublicProtoWithAssociatedType {
106
+ associatedtype A
107
+ func req( ) -> A
93
108
}
94
109
95
110
@rethrows public protocol PublicRethrowsProto {
@@ -100,13 +115,13 @@ public protocol PublicProto {
100
115
func req( ) throws -> Int
101
116
}
102
117
103
- protocol InternalProto {
104
- func goodReq ( ) -> Int // expected-note 2 {{protocol requires function 'goodReq()' with type '() -> Int'; add a stub for conformance}}
105
- func badReq ( ) -> DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
118
+ protocol InternalProtoWithAssociatedType {
119
+ associatedtype A
120
+ func internalReq ( ) -> A
106
121
}
107
122
108
123
protocol InternalProtoConformingToPublicProto : PublicProto {
109
- func internalReq( ) -> DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
124
+ func internalReq( ) -> NoTypecheck
110
125
}
111
126
112
127
public struct PublicStruct {
@@ -115,89 +130,104 @@ public struct PublicStruct {
115
130
@PublicWrapper public var publicWrappedProperty = 3.14
116
131
117
132
public init ( x: Int ) {
118
- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
133
+ self . publicProperty = 1
134
+ _ = NoTypecheck ( )
119
135
}
120
136
121
137
public func publicMethod( ) -> Int {
122
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
138
+ return NoTypecheck . int
123
139
}
124
140
125
141
@MainActor public func publicMainActorMethod( ) -> Int {
126
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
142
+ return NoTypecheck . int
127
143
}
128
144
129
145
public static func publicStaticMethod( ) {
130
- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
146
+ _ = NoTypecheck ( )
131
147
}
132
148
133
- func internalMethod( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
134
- return 1
149
+ func internalMethod( ) -> NoTypecheck {
150
+ return NoTypecheck ( )
135
151
}
136
152
137
- static func internalStaticMethod( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
138
- return 1
153
+ static func internalStaticMethod( ) -> NoTypecheck {
154
+ return NoTypecheck ( )
139
155
}
140
156
}
141
157
142
158
public struct PublicGenericStruct < T> {
159
+ var t : T
160
+
143
161
public func publicMethod( ) -> T {
144
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'T'}}
162
+ _ = NoTypecheck ( )
163
+ return t
145
164
}
146
165
}
147
166
148
- struct InternalStruct : DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
149
- var x : DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
167
+ struct InternalStruct : NoTypecheckProto {
168
+ var x : NoTypecheck
150
169
151
- func f( _ x: DoesNotExist ) { } // expected-error {{cannot find type 'DoesNotExist' in scope} }
170
+ func f( _ x: NoTypecheck ) { }
152
171
}
153
172
154
173
public class PublicClass {
155
174
public var publicProperty : Int
156
175
public var publicPropertyInferredType = " "
157
176
158
177
public init ( x: Int ) {
159
- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
178
+ self . publicProperty = x
179
+ _ = NoTypecheck ( )
160
180
}
161
181
162
- // FIXME: TBDGen causes this constructor to be type checked
163
- // init(_ x: DoesNotExist) {}
182
+ convenience init ( _ x: NoTypecheck ) {
183
+ NoTypecheck . fatalError ( )
184
+ }
164
185
165
186
public func publicMethod( ) -> Int {
166
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
187
+ return NoTypecheck . int
167
188
}
168
189
169
190
public class func publicClassMethod( ) {
170
- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
191
+ _ = NoTypecheck ( )
171
192
}
172
193
173
- // FIXME: TBDGen causes these methods to be type checked
174
- // func internalMethod() -> DoesNotExist {}
175
- // class func internalClassMethod() -> DoesNotExist {}
194
+ public static func publicStaticMethod( ) {
195
+ _ = NoTypecheck ( )
196
+ }
197
+
198
+ func internalMethod( ) -> NoTypecheck {
199
+ return NoTypecheck ( )
200
+ }
201
+
202
+ class func internalClassMethod( ) -> NoTypecheck {
203
+ return NoTypecheck ( )
204
+ }
176
205
}
177
206
178
207
public class PublicDerivedClass : PublicClass { }
179
208
180
- class InternalClass : DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
181
- init ( x: DoesNotExist ) { } // expected-error {{cannot find type 'DoesNotExist' in scope} }
209
+ class InternalClass : NoTypecheckProto {
210
+ init ( x: NoTypecheck ) { }
182
211
}
183
212
184
213
public enum PublicEnum {
185
214
case a
186
215
case b( x: Int )
187
216
188
217
public func publicMethod( ) -> Int {
189
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
218
+ return NoTypecheck . int
190
219
}
191
220
192
221
public var publicComputedVar : Int {
193
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
222
+ return NoTypecheck . int
194
223
}
195
224
}
196
225
197
226
enum InternalEnum {
198
- case bad( DoesNotExist ) // expected-error {{cannot find type 'DoesNotExist' in scope}}
227
+ case bad( NoTypecheck )
199
228
200
- func method( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
229
+ func method( ) -> NoTypecheck {
230
+ return NoTypecheck ( )
201
231
}
202
232
}
203
233
@@ -206,47 +236,66 @@ enum InternalEnum {
206
236
public struct PublicStructConformingToPublicProto : PublicProto {
207
237
public init ( ) { }
208
238
public func req( ) -> Int {
209
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
239
+ return NoTypecheck . int
210
240
}
211
241
}
212
242
213
243
public struct PublicStructIndirectlyConformingToPublicProto : InternalProtoConformingToPublicProto {
214
244
public init ( ) { }
215
245
public func req( ) -> Int {
216
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
246
+ return NoTypecheck . int
247
+ }
248
+
249
+ func internalReq( ) -> NoTypecheck {
250
+ return NoTypecheck ( )
217
251
}
218
252
}
219
253
220
254
public class PublicClassConformingToPublicProto : PublicProto {
221
255
public init ( ) { }
222
256
public func req( ) -> Int {
223
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
257
+ return NoTypecheck . int
224
258
}
225
259
}
226
260
227
261
public class PublicClassInheritingConformanceToPublicProto : PublicClassConformingToPublicProto { }
228
262
229
263
extension String : PublicProto {
230
264
public func req( ) -> Int {
231
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
265
+ return NoTypecheck . int
232
266
}
233
267
}
234
268
235
- extension String : InternalProto { } // expected-error {{type 'String' does not conform to protocol 'InternalProto'}}
269
+ extension String : InternalProtoWithAssociatedType {
270
+ func internalReq( ) -> NoTypecheck {
271
+ return NoTypecheck ( )
272
+ }
273
+ }
236
274
237
275
extension Int : PublicRethrowsProto {
238
276
public func req( ) throws -> Int {
239
- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
277
+ return NoTypecheck . int
240
278
}
241
279
}
242
280
243
- struct InternalStructConformingToPublicProto : PublicProto { // expected-error {{type 'InternalStructConformingToPublicProto' does not conform to protocol 'PublicProto'}}
281
+ struct InternalStructConformingToPublicProto : PublicProtoWithAssociatedType {
282
+ typealias A = NoTypecheck
283
+ func req( ) -> A {
284
+ return NoTypecheck ( )
285
+ }
244
286
}
245
287
246
- extension InternalStruct : PublicProto { // expected-error {{type 'InternalStruct' does not conform to protocol 'PublicProto'}}
288
+ extension InternalStruct : PublicProtoWithAssociatedType {
289
+ typealias A = NoTypecheck
290
+ func req( ) -> A {
291
+ return NoTypecheck ( )
292
+ }
247
293
}
248
294
249
- struct InternalStructConformingToInternalProto : InternalProto { // expected-error {{type 'InternalStructConformingToInternalProto' does not conform to protocol 'InternalProto'}}
295
+ struct InternalStructConformingToInternalProto : InternalProtoWithAssociatedType {
296
+ func internalReq( ) -> NoTypecheck {
297
+ return NoTypecheck ( )
298
+ }
250
299
}
251
300
252
301
struct InternalStructForConstraint { }
@@ -258,15 +307,15 @@ extension PublicGenericStruct: EmptyPublicProto where T == InternalStructForCons
258
307
// MARK: - Type aliases
259
308
260
309
public typealias PublicStructAlias = PublicStruct
261
- typealias InternalTypeAlias = DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
310
+ typealias InternalTypeAlias = NoTypecheck
262
311
263
312
// MARK: - Compiler directives
264
313
265
314
extension PublicStruct {
266
315
#if FLAG
267
316
public static func activeMethod( ) { }
268
317
#else
269
- public static func inactiveMethod( ) -> DoesNotExist { }
318
+ public static func inactiveMethod( ) -> NoTypecheck { }
270
319
#endif
271
320
}
272
321
0 commit comments