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

Cannot set protocol extension property on adopting reference type which is immutable

    XMLWordPrintable

    Details

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

      Description

      I really hate to waste the Swift team's time and distract you from more important things, so if this issue is an intentional restriction of the language then please feel free to archive this "bug" and not respond in any way. Here is the code which doesn't compile even though I wish it did:

       

      protocol A {
        var a: Int { get set }
      }
      
      
      extension A {
        var convenientAccessor: Int {
          get { return a }
          set { a = newValue }
        }
      }
      
      
      class B: A {
        var a: Int = 0
      }
      
      
      func acceptsB (instance: B) {
        instance.a = 1                    // This compiles
        instance.convenientAccessor = 2   // This does not
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jeremy.a.bannister Jeremy Bannister
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: