Uploaded image for project: 'Swift'
  1. Swift
  2. SR-2907

3.0.1p2: @escaping of closure arrays



    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:
    • Environment:

      Linux TrustySwift 4.2.0-27-generic #32~14.04.1-Ubuntu SMP Fri Jan 22 15:32:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
      Welcome to Swift version 3.0.1 (swift-3.0.1-PREVIEW-2). Type :help for assistance.


      Swift 3.0.1 Preview 2 Regression
      The compiler throws an error when arrays or varargs of closures are marked as @escaping:

      helge@TrustySwift:~/dev/Swift/tmp$ swift TestIt.swift
      TestIt.swift:8:28: error: @escaping attribute may only be used in function parameter position
        func add(callbacks cbs: @escaping Callback...) {

      Example which works with Swift 3.0.0:

          public typealias Middleware =
                         ( IncomingMessage, ServerResponse, @escaping Next ) -> Void
          public func connect(middleware: @escaping Middleware...) -> Connect {
            let app = Connect()
            for m in middleware { _ = app.use(m) }
            return app

      I can remove the @escaping and it compiles just fine with 3.0.1p2, which I think is wrong. And as a matter of fact it breaks compilation with Swift 3.0.0:

      /Users/helge/dev/Swift/Noze.io/Sources/connect/Module.swift:21:17: error: invalid conversion from non-escaping function of type '(IncomingMessage, ServerResponse, @escaping (Any...) -> ()) -> ()' to potentially escaping function type 'Middleware' (aka '(IncomingMessage, ServerResponse, @escaping (Any...) -> ()) -> ()')
          _ = app.use(m)
                        as! Middleware

      Summary: @escaping needs to be allowed again on array parameters or vararg parameters.

      P.S.: This is made worse by the fact that you can't even workaround it via:

      #if swift(>=3.0.1)

      but that may be another bug...




            • Assignee:
              milseman Michael Ilseman
              helge Helge Heß
            • Votes:
              0 Vote for this issue
              5 Start watching this issue


              • Created: