Skip to content

Commit 7760280

Browse files
[tests] Add regression tests to SILOptimizer/return.swift
1 parent a627e35 commit 7760280

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

test/SILOptimizer/return.swift

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
func singleBlock() -> Int {
44
_ = 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'}}
66

77
func singleBlock2() -> Int {
88
var y = 0
99
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'}}
1111

1212
enum NoCasesButNotNever {}
1313

@@ -46,7 +46,7 @@ func multipleBlocksSingleMissing(b: Bool) -> (String, Int) {
4646
} else if (y == 0) {
4747
y += 1
4848
}
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)'}}
5050

5151
func multipleBlocksAllMissing(x: Int) -> Int {
5252
var y : Int = x + 1
@@ -56,15 +56,15 @@ func multipleBlocksAllMissing(x: Int) -> Int {
5656
}
5757
var x = 0
5858
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'}}
6060

6161
@_silgen_name("exit") func exit () -> Never
6262

6363
func diagnose_missing_return_in_the_else_branch(i: Bool) -> Int {
6464
if (i) {
6565
exit()
6666
}
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'}}
6868

6969
func diagnose_missing_return_no_error_after_noreturn(i: Bool) -> Int {
7070
if (i) {
@@ -92,7 +92,7 @@ func whileLoop(flag: Bool) -> Int {
9292
}
9393
b += 1
9494
}
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'}}
9696

9797
struct S {}
9898
extension S:ExpressibleByStringLiteral {
@@ -177,7 +177,7 @@ func testSR13753() {
177177
get { 0 }
178178
set { }
179179
}
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 }}
181181
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
182182
// expected-note@-2 {{did you mean to use 'newValue' instead of accessing the property's current value?}}
183183
// expected-warning@-3 {{variable is unused}}
@@ -203,7 +203,7 @@ func testSR13753() {
203203
// expected-warning@-1 {{setter argument 'newValue' was never used, but the property was accessed}}
204204
// expected-note@-2 {{did you mean to use 'newValue' instead of accessing the property's current value?}}
205205
// 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'}}
207207

208208
let _ : () -> Int = {
209209
var x : Int = 0 // expected-warning {{variable 'x' was never mutated; consider changing to 'let' constant}}
@@ -213,3 +213,39 @@ func testSR13753() {
213213
//expected-warning@-1{{variable is unused}}
214214
}
215215
}
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

Comments
 (0)