|
| 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. |
| 5 | + |
| 6 | +// MARK: - Global functions |
| 7 | + |
| 8 | +public func publicFunc() -> Int { |
| 9 | + return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}} |
| 10 | +} |
| 11 | + |
| 12 | +public func publicFuncWithDefaultArg(_ x: Int = 1) -> Int { |
| 13 | + return doesNotExist() // expected-error {{cannot find 'doesNotExist' in scope}} |
| 14 | +} |
| 15 | + |
| 16 | +package func packageFunc() -> Int { |
| 17 | + return false // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}} |
| 18 | +} |
| 19 | + |
| 20 | +func internalFunc() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}} |
| 21 | + return 1 |
| 22 | +} |
| 23 | + |
| 24 | +@inlinable func inlinableFunc() -> Int { |
| 25 | + return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}} |
| 26 | +} |
| 27 | + |
| 28 | +private func privateFunc() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}} |
| 29 | + return 1 |
| 30 | +} |
| 31 | + |
| 32 | +public func constrainedGenericPublicFunction<T>(_ t: T) where T: PublicProto { |
| 33 | + doesNotExist() // expected-error {{cannot find 'doesNotExist' in scope}} |
| 34 | +} |
| 35 | + |
| 36 | +@available(SwiftStdlib 5.1, *) |
| 37 | +public func publicFuncWithOpaqueReturnType() -> some PublicProto { // expected-note {{opaque return type declared here}} |
| 38 | + return 1 // expected-error {{return type of global function 'publicFuncWithOpaqueReturnType()' requires that 'Int' conform to 'PublicProto'}} |
| 39 | +} |
| 40 | + |
| 41 | +@available(SwiftStdlib 5.1, *) |
| 42 | +@_alwaysEmitIntoClient public func publicAEICFuncWithOpaqueReturnType() -> some Any { |
| 43 | + if #available(macOS 20, *) { |
| 44 | + return 3 |
| 45 | + } else { |
| 46 | + return "hi" |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +// MARK: - Nominal types |
| 51 | + |
| 52 | +public protocol PublicProto { |
| 53 | + func req() -> Int |
| 54 | +} |
| 55 | + |
| 56 | +protocol InternalProto { |
| 57 | + // FIXME: Serialization causes typechecking of protocols regardless of access level |
| 58 | +// func req() -> DoesNotExist |
| 59 | +} |
| 60 | + |
| 61 | +public struct PublicStruct { |
| 62 | + // FIXME: Test properties |
| 63 | + |
| 64 | + public func publicMethod() -> Int { |
| 65 | + return true // expected-error {{cannot convert return expression of type 'Bool' to return type 'Int'}} |
| 66 | + } |
| 67 | + |
| 68 | + func internalMethod() -> DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}} |
| 69 | + return 1 |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +struct InternalStruct: DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}} |
| 74 | + var x: DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}} |
| 75 | + |
| 76 | + func f(_ x: DoesNotExist) {} // expected-error {{cannot find type 'DoesNotExist' in scope}} |
| 77 | +} |
| 78 | + |
| 79 | +// FIXME: Test enums |
| 80 | +// FIXME: Test conformances |
| 81 | +// FIXME: Test global vars |
0 commit comments