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

Enforce @escaping for for all but the most trivial uses of captured variables.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:

      Description

      This is a source compatibility bug.

      A nested function used in an @escaping context must produce a type
      checker error. In the example below, we expect a diagnostic:

      error: nested function with an implicitly captured inout parameter can only be used as a non-escaping argument

      Instead we get an error in diagnose exclusivity, but only in asserts builds, which is not good enough to protect against undefined behavior.

      Applied argument must be @noescape function type: %21 = argument of bb3 : $@callee_guaranteed () -> ()
      A partial_apply with @inout_aliasable may only be used as a @noescape function type argument.
      UNREACHABLE executed at /s/s/swift/lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp:1085!
      func doit(_ f: @escaping ()->()) { f() }
      
      public func outerFoo1(x: inout Int) {
       func innerFoo1() {
        x = 1
       }
       func innerFoo2() {
        x = 2
       }
       doit(x == 0 ? innerFoo1 : innerFoo2)
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                atrick Andrew Trick
              • Votes:
                1 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: