Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-8805] Cannot set protocol extension property on adopting reference type which is immutable #51313

Closed
jeremyabannister opened this issue Sep 20, 2018 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@jeremyabannister
Copy link

Previous ID SR-8805
Radar None
Original Reporter @jeremyabannister
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: a287be58d0bdbdb7b069381c1a1f5ce1

duplicates:

  • SR-142 mutating function in protocol extension erroneously requires var declaration of class variables

Issue 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
}
@belkadan
Copy link
Contributor

It's not a bug, but it is confusing. Check out the explanation in SR-142.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

2 participants