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
|
// RUN: %target-swift-frontend %s -emit-sil -verify
// MARK: Relocated Test Cases
// Missing return diagnostics used to also be implemented during parsing/AST
// construction in addition to the SIL passes. Some existing test cases have
// been moved here after removing the earlier phases' diagnostics in favor of
// those implemented via the SIL passes.
// MARK: `decl/subscript/subscripting`
struct MissingGetterSubscript1 {
subscript (i : Int) -> Int {
} // expected-error {{missing return in getter expected to return 'Int'}}
}
// MARK: `decl/var/properties`
struct X {}
var x13: X {} // expected-error {{missing return in getter expected to return 'X'}}
struct X14 {}
extension X14 {
var x14: X {
} // expected-error {{missing return in getter expected to return 'X'}}
}
// https://github.com/apple/swift/issues/57936
enum E1_57936 {
var foo: Int {} // expected-error{{missing return in getter expected to return 'Int'}}
}
enum E2_57936<T> {
var foo: T {} // expected-error{{missing return in getter expected to return 'T'}}
}
// MARK: `decl/var/result_builders`
@resultBuilder
struct Maker {
static func buildBlock() -> Int { 42 }
}
@Maker
var globalWithEmptyImplicitGetter: Int {}
// MARK: `Parse/omit_return`
var fv_nop: () {
}
var fv_missing: String {
} // expected-error {{missing return in getter expected to return 'String'}}
enum S_nop {
subscript() -> () {
}
}
enum S_missing {
subscript() -> String {
} // expected-error {{missing return in getter expected to return 'String'}}
}
// MARK: `Sema/generic-subscript`
struct S_generic_subscript_missing_return {
subscript<Value>(x: Int) -> Value {
} // expected-error {{missing return in getter expected to return 'Value'}}
}
// MARK: New Test Cases
enum MyEmptyType {}
extension MyEmptyType {
var i: Int {} // expected-error{{missing return in getter expected to return 'Int'}}
var n: MyEmptyType {} // expected-error{{getter with uninhabited return type 'MyEmptyType' is missing call to another never-returning function on all paths}}
static subscript<A>(root: MyEmptyType) -> A {}
subscript(_ e: MyEmptyType) -> Int {}
subscript<T>(_ e: MyEmptyType) -> T {}
subscript(_ i: Int) -> Int {} // expected-error{{missing return in getter expected to return 'Int'}}
subscript<T>(_ p: Int) -> T {} // expected-error{{missing return in getter expected to return 'T'}}
subscript(_ i: Int) -> Self {} // expected-error{{getter with uninhabited return type 'MyEmptyType' is missing call to another never-returning function on all paths}}
subscript(_ s: Self) -> Self {}
static func unreachable_static_implicit_return(_ e: MyEmptyType) -> Int {}
func unreachable(_ e: MyEmptyType) -> Int { // expected-note{{'e' is of type 'MyEmptyType' which cannot be constructed because it is an enum with no cases}}
42 // expected-warning{{will never be executed}}
}
// FIXME: should these produce warnings since they implicity take an uninhabited 'self' param?
func implicitly_unreachable() { _ = 42 }
func implicitly_unreachable_implicit_return() -> Int { 42 }
}
extension Never {
var i: Int {} // expected-error{{missing return in getter expected to return 'Int'}}
var n: Never {} // expected-error{{getter with uninhabited return type 'Never' is missing call to another never-returning function on all paths}}
static subscript<A>(root: Never) -> A {}
subscript(_ n: Never) -> Int {}
subscript<T>(_ e: Never) -> T {}
subscript(_ i: Int) -> Int {} // expected-error{{missing return in getter expected to return 'Int'}}
subscript<T>(_ p: Int) -> T {} // expected-error{{missing return in getter expected to return 'T'}}
subscript(_ i: Int) -> Self {} // expected-error{{getter with uninhabited return type 'Never' is missing call to another never-returning function on all paths}}
subscript(_ s: Self) -> Self {}
static func unreachable_static_implicit_return(_ n: Never) -> Int {}
func unreachable(_ n: Never) -> Int { // expected-note{{'n' is of type 'Never' which cannot be constructed because it is an enum with no cases}}
42 // expected-warning{{will never be executed}}
}
// FIXME: should these produce unreachable code warnings since they implicity take an uninhabited 'self' param?
func implicitly_unreachable() { _ = 42 }
func implicitly_unreachable_implicit_return() -> Int { 42 }
}
enum InhabitedType {
case inhabitant
// Uninhabited params
subscript(_ n: Never) -> Int {}
subscript<T>(_ e: Never) -> T {}
subscript(_ v: MyEmptyType, e: Int) -> Never {}
// Inhabited params
subscript(_ i: Int) -> Int {} // expected-error{{missing return in getter expected to return 'Int'}}
subscript(_ j: Int) -> Void {}
subscript(_ k: Int) -> Never {} // expected-error{{getter with uninhabited return type 'Never' is missing call to another never-returning function on all paths}}
// FIXME: ^ this diagnostic should probably use the word 'subscript' rather than 'getter'
}
|