2
2
3
3
func singleBlock( ) -> Int {
4
4
_ = 0
5
- } // expected-error {{missing return in a function expected to return 'Int'}}
5
+ } // expected-error {{missing return in a global function expected to return 'Int'}}
6
6
7
7
func singleBlock2( ) -> Int {
8
8
var y = 0
9
9
y += 1
10
- } // expected-error {{missing return in a function expected to return 'Int'}}
10
+ } // expected-error {{missing return in a global function expected to return 'Int'}}
11
11
12
12
enum NoCasesButNotNever { }
13
13
@@ -46,7 +46,7 @@ func multipleBlocksSingleMissing(b: Bool) -> (String, Int) {
46
46
} else if ( y == 0 ) {
47
47
y += 1
48
48
}
49
- } // expected-error {{missing return in a function expected to return '(String, Int)'}}
49
+ } // expected-error {{missing return in a global function expected to return '(String, Int)'}}
50
50
51
51
func multipleBlocksAllMissing( x: Int ) -> Int {
52
52
var y : Int = x + 1
@@ -56,15 +56,15 @@ func multipleBlocksAllMissing(x: Int) -> Int {
56
56
}
57
57
var x = 0
58
58
x += 1
59
- } // expected-error {{missing return in a function expected to return 'Int'}}
59
+ } // expected-error {{missing return in a global function expected to return 'Int'}}
60
60
61
61
@_silgen_name ( " exit " ) func exit ( ) -> Never
62
62
63
63
func diagnose_missing_return_in_the_else_branch( i: Bool ) -> Int {
64
64
if ( i) {
65
65
exit ( )
66
66
}
67
- } // expected-error {{missing return in a function expected to return 'Int'}}
67
+ } // expected-error {{missing return in a global function expected to return 'Int'}}
68
68
69
69
func diagnose_missing_return_no_error_after_noreturn( i: Bool ) -> Int {
70
70
if ( i) {
@@ -92,7 +92,7 @@ func whileLoop(flag: Bool) -> Int {
92
92
}
93
93
b += 1
94
94
}
95
- } //expected-error {{missing return in a function expected to return 'Int'}}
95
+ } //expected-error {{missing return in a global function expected to return 'Int'}}
96
96
97
97
struct S { }
98
98
extension S : ExpressibleByStringLiteral {
@@ -177,7 +177,7 @@ func testSR13753() {
177
177
get { 0 }
178
178
set { }
179
179
}
180
- x // expected-error {{missing return in a function expected to return 'Int'; did you mean to return the last expression?}} {{5-5=return }}
180
+ x // expected-error {{missing return in a local function expected to return 'Int'; did you mean to return the last expression?}} {{5-5=return }}
181
181
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
182
182
// expected-note@-2 {{did you mean to use 'newValue' instead of accessing the property's current value?}}
183
183
// expected-warning@-3 {{variable is unused}}
@@ -203,7 +203,7 @@ func testSR13753() {
203
203
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
204
204
// expected-note@-2 {{did you mean to use 'newValue' instead of accessing the property's current value?}}
205
205
// expected-warning@-3 {{variable is unused}}
206
- } // expected-error {{missing return in a function expected to return 'Int'}}
206
+ } // expected-error {{missing return in a local function expected to return 'Int'}}
207
207
208
208
let _ : ( ) -> Int = {
209
209
var x : Int = 0 // expected-warning {{variable 'x' was never mutated; consider changing to 'let' constant}}
@@ -213,3 +213,39 @@ func testSR13753() {
213
213
//expected-warning@-1{{variable is unused}}
214
214
}
215
215
}
216
+
217
+ // SR-14505
218
+ struct SR14505 {
219
+ let b = true
220
+ var x : Int {
221
+ if b {
222
+ return 0
223
+ }
224
+ } // expected-error {{missing return in a getter expected to return 'Int'}}
225
+
226
+ var y : Int {
227
+ get {
228
+ if b {
229
+ return 0
230
+ }
231
+ } // expected-error {{missing return in a getter expected to return 'Int'}}
232
+ set { }
233
+ }
234
+ }
235
+
236
+ class SR14505_C {
237
+ static let a = false
238
+ let b = true
239
+
240
+ func method( ) -> Int {
241
+ if b {
242
+ return 0
243
+ }
244
+ } // expected-error {{missing return in a instance method expected to return 'Int'}}
245
+
246
+ class func method1( ) -> Int {
247
+ if a {
248
+ return 0
249
+ }
250
+ } // expected-error {{missing return in a class method expected to return 'Int'}}
251
+ }
0 commit comments