Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15201,7 +15201,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
locator.endsWith<LocatorPathElt::SubscriptMember>())
? 1
: 0;

// An overload choice that isn't settable is least interesting for diagnosis.
if (auto overload = findSelectedOverloadFor(getCalleeLocator(fix->getLocator()))) {
if (auto *var = dyn_cast_or_null<VarDecl>(overload->choice.getDeclOrNull())) {
impact += !var->isSettableInSwift(DC) ? 1 : 0;
}
}
return recordFix(fix, impact) ? SolutionKind::Error : SolutionKind::Solved;
}

Expand Down
13 changes: 13 additions & 0 deletions test/Sema/immutability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -762,3 +762,16 @@ struct S2<T> {
// expected-note@-1 {{add explicit 'S2<T>.' to refer to mutable static property of 'S2<T>'}} {{5-5=S2<T>.}}
}
}

// SR-3680, https://github.com/apple/swift/issues/46265
protocol HasFoo {
var foo: String { get }
}
protocol CanSetFoo {
var foo: String { get set }
}
extension HasFoo where Self: CanSetFoo {
func bar() { // expected-note {{mark method 'mutating' to make 'self' mutable}}{{3-3=mutating }}
self.foo = "bar" // expected-error {{cannot assign to property: 'self' is immutable}}
}
}