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

Mutating method in protocol extension always requires variable to be `var`

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: None
    • Labels:
      None
    • Environment:

      Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
      Target: x86_64-apple-darwin18.6.0

      Description

      Consider the following code:

      protocol ProtocolWithMutableMethod {
         mutating func mutateStuff()
      }
      
      extension ProtocolWithMutableMethod {
         mutating func mutateStuff() {
         }
      }
      
      struct MyClass: ProtocolWithMutableMethod {
      }
      
      let object = MyClass()
      object.mutateStuff()
      

      The compiler complains “Cannot use mutating member on immutable value: 'object' is a 'let’ constant” even though object is clearly a reference type where everything is mutable.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              fumoboy007 Darren Mo
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: