Skip to content

Commit 58fbd1b

Browse files
committed
Add some testcases for some radars that are fixed on master.
1 parent 405f9f5 commit 58fbd1b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/Constraints/lvalues.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,30 @@ func testImmutableUnsafePointer(p: UnsafePointer<Int>) {
207207
// inout crashes compiler
208208
let g = { x in f0(x) } // expected-error{{passing value of type 'Int' to an inout parameter requires explicit '&'}} {{19-19=&}}
209209

210+
// <rdar://problem/17245353> Crash with optional closure taking inout
211+
func rdar17245353() {
212+
typealias Fn = (inout Int) -> ()
213+
func getFn() -> Fn? { return nil }
214+
215+
let _: (inout UInt, UInt) -> Void = { $0 += $1 }
216+
}
217+
218+
// <rdar://problem/23131768> Bugs related to closures with inout parameters
219+
func rdar23131768() {
220+
func f(g: (inout Int) -> Void) { var a = 1; g(&a); print(a) }
221+
f { $0 += 1 } // Crashes compiler
222+
223+
func f2(g: (inout Int) -> Void) { var a = 1; g(&a); print(a) }
224+
f2 { $0 = $0 + 1 } // previously error: Cannot convert value of type '_ -> ()' to expected type '(inout Int) -> Void'
225+
226+
func f3(g: (inout Int) -> Void) { var a = 1; g(&a); print(a) }
227+
f3 { (inout v: Int) -> Void in v += 1 }
228+
}
229+
230+
// <rdar://problem/23331567> Swift: Compiler crash related to closures with inout parameter.
231+
func r23331567(fn: (inout x: Int) -> Void) {
232+
var a = 0
233+
fn(x: &a)
234+
}
235+
r23331567 { $0 += 1 }
236+

0 commit comments

Comments
 (0)