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

Nested functions should allow escaping attributes, be @noescape by default

    XMLWordPrintable

    Details

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

      Swift 6f743dba7c707def90af17aae71c32fea95e84d5

      Description

      The following code fails to compile, as the reference to 'callback' in 'nestedFunc()' is considered possibly-escaping.

      func doSomething(callback: (Bool)->()) {
      	
      	func nestedFunc() {
      		callback(true)
      	}
      	nestedFunc()
      }
      
      /Users/karl/Desktop/test.swift:4:3: error: declaration closing over non-escaping parameter 'callback' may allow it to escape
                      callback(true)
                      ^
      /Users/karl/Desktop/test.swift:1:18: note: parameter 'callback' is implicitly non-escaping
      func doSomething(callback: (Bool)->()) {
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                slavapestov Slava Pestov
                Reporter:
                kawa Karl
              • Votes:
                2 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: