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-4227] Can't call mutating protocol extension method in class init #46810

Closed
dabrahams opened this issue Mar 12, 2017 · 1 comment
Closed

Comments

@dabrahams
Copy link
Collaborator

dabrahams commented Mar 12, 2017

Previous ID SR-4227
Radar None
Original Reporter @dabrahams
Type Bug
Status Closed
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 456981ccaf1536e627d612fe4a6f486c

duplicates:

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

Issue Description:

protocol P {
  associatedtype Header
  var header: Header { get set }
}

extension P {
  mutating func f() {
    withUnsafePointer(to: &self.header) { print($0) }
  }
}

class X : P {
  var header: Int = 0
  init() {
    withUnsafePointer(to: &self.header) { print($0) }

    // This works:
    var me = self
    me.f()
    
    // But this doesn't:
    self.f() // error: cannot use mutating member on immutable value: 'self' is immutable
  }
}

X()
@belkadan
Copy link
Contributor

belkadan commented Mar 14, 2017

Consolidating.

@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
Projects
None yet
Development

No branches or pull requests

2 participants