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

Missing checks of inout/mutating captures

    XMLWordPrintable

    Details

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

      Xcode Version 10.0 (10A255)

      Description

      The following code causes a compile-time error correctly.

      func run(_ body: @escaping () -> Void) { body() }
      
      
      struct S {
          var a: Int = 3
          
          mutating func foo() {
              func _foo() {
                  if a == 0 { return }
                  a -= 1
                  print(a)
                  run(_foo)
              }
              _foo()
          }
      }
      
      
      var s = S()
      s.foo()
      
      error: nested function with an implicitly captured inout parameter can only be used as a non-escaping argument
                   run(_foo)
                   ^
      

      However, when `run(_foo)` is changed to `run { _foo() }`, it can be compiled. I guess the compiler lacks some checks.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                koher Yuta Koshizawa
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: