Nonescaping parameter type spelling

In the following fragment:

func foo(escaping: @escaping () -> (), nonescaping: () -> ()) {
    let a = escaping            // ok
    let b = nonescaping         // ok
    print(type(of: a))          // () -> ()
    print(type(of: b))          // () -> ()
    let c: () -> () = escaping  // ok
    let d: () -> () = nonescaping // πŸ›‘ Using non-escaping parameter 'nonescaping' in a context expecting an @escaping closure
}

foo(escaping: {}, nonescaping: {})

both escaping and non escaping closure types are printed as () -> (), although this is apparently not the whole story and if I use this type in the explicit type position of a variable declaration the type doesn't match the nonescaping parameter. Is this type inexpressible in Swift?

3 Likes

I think it is comparable to let vs. var:
No different type, but some restriction on what you can do with the variable/value.

1 Like
1 Like