Skip to content

[SR-3680] Incorrect error about readonly property in protocol extension that conforms to another protocol #46265

@lilyball

Description

@lilyball
mannequin
Previous ID SR-3680
Radar None
Original Reporter @lilyball
Type Bug
Environment

Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: f6c5147ee90b20316576f2735e2456c7

Issue Description:

Given the following code:

protocol HasFoo { var foo: String { get } } protocol CanSetFoo { var foo: String { get set } } extension HasFoo where Self: CanSetFoo { func bar() { self.foo = "bar" } }

The method bar() can't compile because it's not marked as mutating. But the error is wrong. The expected error is:

bar.swift:9:19: error: cannot assign to property: 'self' is immutable self.foo = "bar" ~~~~ ^ bar.swift:8:20: note: mark method 'mutating' to make 'self' mutable func bar() { ^ mutating 

But the actual error the compiler returns is:

bar.swift:9:18: error: cannot assign to property: 'foo' is a get-only property self.foo = "bar" ~~~~~~~~ ^ 

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementationtype checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions