File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -207,3 +207,30 @@ func testImmutableUnsafePointer(p: UnsafePointer<Int>) {
207
207
// inout crashes compiler
208
208
let g = { x in f0 ( x) } // expected-error{{passing value of type 'Int' to an inout parameter requires explicit '&'}} {{19-19=&}}
209
209
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
+
You can’t perform that action at this time.
0 commit comments