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

Implicit inout allowed with expression pattern matching

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: In Progress
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
    • Environment:

      Swift version 5.1-dev (LLVM c5340df2d1, Swift 0cbbb21723)
      Target: x86_64-apple-darwin18.5.0

      Description

      The following is legal:

      func ~= (pattern: inout Int, value: Int) -> Bool {
        pattern = value
        return true
      }
      
      var x = 0
      
      switch 49 {
      case x:
        print("yup")
      default:
        print("nope")
      }
      
      print(x) // 49
      

      But we probably shouldn't allow the pattern x to be used as an implicit inout argument. This is source breaking, but I would hope nobody is relying on this.

        Attachments

          Activity

            People

            • Assignee:
              suyashsrijan Suyash Srijan
              Reporter:
              originaluser2 Hamish Knight
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: