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

Cannot assign to property of an instance of a class declared in a protocol extension

    XMLWordPrintable

    Details

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

      macOS, Swift 3.0 (release), XCode 8

      Description

      This code:

      protocol Bar {}
      
      extension Bar {
          var property: String {
              get {
                  return ""
              }
              set {
                  
              }
          }
      }
      
      class Foo: Bar {}
      
      let foo = Foo()
      
      foo.property = "?!" // error: cannot assign to property: 'foo' is a 'let' constant
      

      will not compile, but it should.

      The thing is, if foo were of type Bar, then I would have had to make Bar a class-only protocol in order to make it compile. But foo is of type Foo.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              broadway_lamb Sergej Jaskiewicz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: