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

dabrahams opened this issue Mar 12, 2017 · 1 comment


Copy link

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


  • 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
    // But this doesn't:
    self.f() // error: cannot use mutating member on immutable value: 'self' is immutable

Copy link

belkadan commented Mar 14, 2017


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

No branches or pull requests

2 participants