-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdeclarationsFeature: declarationsFeature: declarationsextensionFeature → declarations: `extension` declarationsFeature → declarations: `extension` declarationsmutabilityFeature: storage mutabilityFeature: storage mutabilityprotocolFeature → type declarations: Protocol declarationsFeature → type declarations: Protocol declarationsswift 5.7type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
Description
Mutating method on extension of AnyObject
-constrained protocol results in unexpected "cannot assign to property: 'self' is immutable"
error.
Steps to reproduce
Attempt to build the following code in Swift 5.7 (playground):
class MyClass: MyProtocol {
var property: String = ""
}
protocol ProtocolSettable {
var property: String { get set }
}
protocol MyProtocol: AnyObject, ProtocolSettable {
}
extension MyProtocol {
func updateProperty() {
// 🛑 "cannot assign to property: 'self' is immutable"
property = "test"
}
}
It fails to compile with this error:
/main.swift:15:5: error: cannot assign to property: 'self' is immutable
property = "test"
Expected behavior
Since MyProtocol
is guaranteed to be a class, I expect this to compile.
erichoracekykws
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdeclarationsFeature: declarationsFeature: declarationsextensionFeature → declarations: `extension` declarationsFeature → declarations: `extension` declarationsmutabilityFeature: storage mutabilityFeature: storage mutabilityprotocolFeature → type declarations: Protocol declarationsFeature → type declarations: Protocol declarationsswift 5.7type checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis