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

mutating function in protocol extension erroneously requires `var` declaration of class variables

    XMLWordPrintable

    Details

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

      Version 7.1.1 (7B1005)

      Description

      Hello,

      The following code won't compile, when it should:

      protocol P { }
      
      extension P {
          mutating func m() { }
      }
      
      class C : P { }
      
      let c = C()
      // error: cannot use mutating member on immutable value: 'c' is a 'let' constant
      c.m()
      

      This error should not exist: the type of variable c is C. Mutating methods can not be added to C, because of the 'mutating' isn't valid on methods in classes or class-bound protocols error. Hence the mutating qualifier of P.m should not apply to c, and c should be able to be declared as a let variable.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              groue Gwendal Roué
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: