-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Setter has incorrect mutating-ness inside class-constrained protocol extension #26669
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
Conversation
cc @slavapestov |
Technically source-breaking, but I kinda hope no one is depending on this. protocol SR_11298_P {
init()
}
class SR_11298_C: SR_11298_P {
var property: String = ""
required init() {}
}
extension SR_11298_P where Self: SR_11298_C {
var wrappingProperty: String {
get { return property }
set { self = .init() }
}
}
let origInstance = SR_11298_C()
var instance = origInstance
instance.wrappingProperty = ""
print(instance === origInstance) |
@swift-ci Please test |
@swift-ci Please test source compatibility |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks, @theblixguy! |
Should we make a note of this in the changelog? Note that this change can also break code where the setter delegates to another mutating requirement or extension member, such as: protocol P {
var property: String { get set }
}
extension P where Self : AnyObject {
var wrappingProperty: String {
get { property }
set { property = newValue }
}
} |
Ah, hm. That might be a more serious concern, especially since people are already confused about why protocol methods can be |
Reverting for now. |
@theblixguy Can you create a PR that adds a test case for the current behavior, including @hamishknight's example? I'm not sure it's tested anywhere in our suite and we want to make sure any change is intentional. |
Sure. I’ve also created a forum thread to discuss this. |
If we have a class-constrained protocol extension, where the protocol does not impose a class requirement, then the setter is incorrectly inferred to be mutating by default.
Resolves SR-11298.