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+ }
512
613// MARK: - Global functions
714
815public func publicFunc( ) -> Int {
9- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
16+ return NoTypecheck . int
1017}
1118
1219public func publicFuncWithDefaultArg( _ x: Int = 1 ) -> Int {
13- return doesNotExist ( ) // expected-error {{cannot find 'doesNotExist' in scope}}
20+ return NoTypecheck . int
1421}
1522
1623package func packageFunc( ) -> Int {
17- return false // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
24+ return NoTypecheck . int
1825}
1926
20- func internalFunc( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
21- return 1
27+ func internalFunc( ) -> NoTypecheck {
28+ return NoTypecheck ( )
2229}
2330
2431@inlinable func inlinableFunc( ) -> Int {
2532 return 1
2633}
2734
28- private func privateFunc( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
29- return 1
35+ private func privateFunc( ) -> NoTypecheck {
36+ return NoTypecheck ( )
3037}
3138
3239public func constrainedGenericPublicFunction< T> ( _ t: T ) where T: PublicProto {
33- doesNotExist ( ) // expected-error {{cannot find 'doesNotExist' in scope}}
40+ _ = NoTypecheck ( )
3441}
3542
3643@_specialize ( exported: true , where T == PublicProto)
3744public func publicSpecializedFunc< T> ( _ t: T ) -> T {
38- return doesNotExist ( ) // expected-error {{cannot find 'doesNotExist' in scope}}
45+ _ = NoTypecheck ( )
46+ return t
3947}
4048
4149@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 ( )
4452}
4553
4654@available ( SwiftStdlib 5 . 1 , * )
@@ -58,38 +66,45 @@ public func publicFuncWithOpaqueReturnType() -> some PublicProto { // expected-n
5866public struct PublicWrapper < T> {
5967 public var wrappedValue : T {
6068 get {
61- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
69+ NoTypecheck . fatalError ( )
6270 }
6371 set {
64- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
72+ NoTypecheck . fatalError ( )
6573 }
6674 }
6775
6876 public var projectedValue : PublicWrapper { self }
6977
7078 public init ( wrappedValue value: T ) {
71- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
79+ NoTypecheck . fatalError ( )
7280 }
7381}
7482
7583@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+ }
7787
7888// MARK: - Global vars
7989
8090public var publicGlobalVar : Int = 0
8191public var publicGlobalVarInferredType = " "
8292public var ( publicGlobalVarInferredTuplePatX, publicGlobalVarInferredTuplePatY) = ( 0 , 1 )
8393
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 ( )
8696
8797// MARK: - Nominal types
8898
8999public protocol EmptyPublicProto { }
90100
91101public 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
93108}
94109
95110@rethrows public protocol PublicRethrowsProto {
@@ -100,13 +115,13 @@ public protocol PublicProto {
100115 func req( ) throws -> Int
101116}
102117
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
106121}
107122
108123protocol InternalProtoConformingToPublicProto : PublicProto {
109- func internalReq( ) -> DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
124+ func internalReq( ) -> NoTypecheck
110125}
111126
112127public struct PublicStruct {
@@ -115,89 +130,104 @@ public struct PublicStruct {
115130 @PublicWrapper public var publicWrappedProperty = 3.14
116131
117132 public init ( x: Int ) {
118- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
133+ self . publicProperty = 1
134+ _ = NoTypecheck ( )
119135 }
120136
121137 public func publicMethod( ) -> Int {
122- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
138+ return NoTypecheck . int
123139 }
124140
125141 @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
127143 }
128144
129145 public static func publicStaticMethod( ) {
130- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
146+ _ = NoTypecheck ( )
131147 }
132148
133- func internalMethod( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
134- return 1
149+ func internalMethod( ) -> NoTypecheck {
150+ return NoTypecheck ( )
135151 }
136152
137- static func internalStaticMethod( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
138- return 1
153+ static func internalStaticMethod( ) -> NoTypecheck {
154+ return NoTypecheck ( )
139155 }
140156}
141157
142158public struct PublicGenericStruct < T> {
159+ var t : T
160+
143161 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
145164 }
146165}
147166
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
150169
151- func f( _ x: DoesNotExist ) { } // expected-error {{cannot find type 'DoesNotExist' in scope} }
170+ func f( _ x: NoTypecheck ) { }
152171}
153172
154173public class PublicClass {
155174 public var publicProperty : Int
156175 public var publicPropertyInferredType = " "
157176
158177 public init ( x: Int ) {
159- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
178+ self . publicProperty = x
179+ _ = NoTypecheck ( )
160180 }
161181
162- // FIXME: TBDGen causes this constructor to be type checked
163- // init(_ x: DoesNotExist) {}
182+ convenience init ( _ x: NoTypecheck ) {
183+ NoTypecheck . fatalError ( )
184+ }
164185
165186 public func publicMethod( ) -> Int {
166- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
187+ return NoTypecheck . int
167188 }
168189
169190 public class func publicClassMethod( ) {
170- _ = DoesNotExist ( ) // expected-error {{cannot find 'DoesNotExist' in scope}}
191+ _ = NoTypecheck ( )
171192 }
172193
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+ }
176205}
177206
178207public class PublicDerivedClass : PublicClass { }
179208
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 ) { }
182211}
183212
184213public enum PublicEnum {
185214 case a
186215 case b( x: Int )
187216
188217 public func publicMethod( ) -> Int {
189- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
218+ return NoTypecheck . int
190219 }
191220
192221 public var publicComputedVar : Int {
193- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
222+ return NoTypecheck . int
194223 }
195224}
196225
197226enum InternalEnum {
198- case bad( DoesNotExist ) // expected-error {{cannot find type 'DoesNotExist' in scope}}
227+ case bad( NoTypecheck )
199228
200- func method( ) -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
229+ func method( ) -> NoTypecheck {
230+ return NoTypecheck ( )
201231 }
202232}
203233
@@ -206,47 +236,66 @@ enum InternalEnum {
206236public struct PublicStructConformingToPublicProto : PublicProto {
207237 public init ( ) { }
208238 public func req( ) -> Int {
209- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
239+ return NoTypecheck . int
210240 }
211241}
212242
213243public struct PublicStructIndirectlyConformingToPublicProto : InternalProtoConformingToPublicProto {
214244 public init ( ) { }
215245 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 ( )
217251 }
218252}
219253
220254public class PublicClassConformingToPublicProto : PublicProto {
221255 public init ( ) { }
222256 public func req( ) -> Int {
223- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
257+ return NoTypecheck . int
224258 }
225259}
226260
227261public class PublicClassInheritingConformanceToPublicProto : PublicClassConformingToPublicProto { }
228262
229263extension String : PublicProto {
230264 public func req( ) -> Int {
231- return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}}
265+ return NoTypecheck . int
232266 }
233267}
234268
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+ }
236274
237275extension Int : PublicRethrowsProto {
238276 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
240278 }
241279}
242280
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+ }
244286}
245287
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+ }
247293}
248294
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+ }
250299}
251300
252301struct InternalStructForConstraint { }
@@ -258,15 +307,15 @@ extension PublicGenericStruct: EmptyPublicProto where T == InternalStructForCons
258307// MARK: - Type aliases
259308
260309public typealias PublicStructAlias = PublicStruct
261- typealias InternalTypeAlias = DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
310+ typealias InternalTypeAlias = NoTypecheck
262311
263312// MARK: - Compiler directives
264313
265314extension PublicStruct {
266315#if FLAG
267316 public static func activeMethod( ) { }
268317#else
269- public static func inactiveMethod( ) -> DoesNotExist { }
318+ public static func inactiveMethod( ) -> NoTypecheck { }
270319#endif
271320}
272321
0 commit comments