Skip to content

Commit b331a45

Browse files
committed
[CS] Improve mutability diag for dynamic lookup
Look at the callee locator to add some additional info to the diagnostic.
1 parent f045350 commit b331a45

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,8 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
16141614
}
16151615
}
16161616

1617-
if (auto resolvedOverload = getOverloadChoiceIfAvailable(getLocator())) {
1617+
if (auto resolvedOverload =
1618+
getCalleeOverloadChoiceIfAvailable(getLocator())) {
16181619
if (resolvedOverload->choice.getKind() ==
16191620
OverloadChoiceKind::DynamicMemberLookup)
16201621
subElementDiagID = diag::assignment_dynamic_property_has_immutable_base;

test/attr/attr_dynamic_member_lookup.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ struct NonMutSettable {
3636

3737
func test(a: Gettable, b: Settable, c: MutGettable, d: NonMutSettable) {
3838
global = a.wyverns
39-
a.flavor = global // expected-error {{cannot assign to property: 'a' is a 'let' constant}}
39+
a.flavor = global // expected-error {{cannot assign through dynamic lookup property: 'a' is a 'let' constant}}
4040

4141
global = b.flavor
42-
b.universal = global // expected-error {{cannot assign to property: 'b' is a 'let' constant}}
42+
b.universal = global // expected-error {{cannot assign through dynamic lookup property: 'b' is a 'let' constant}}
4343
b.thing += 1 // expected-error {{left side of mutating operator isn't mutable: 'b' is a 'let' constant}}
4444

4545
var bm = b
@@ -318,7 +318,7 @@ class DerivedClassWithSetter : BaseClass {
318318
func testOverrideSubscript(a: BaseClass, b: DerivedClassWithSetter) {
319319
let x = a.frotz + b.garbalaz
320320
b.baranozo = x
321-
a.balboza = 12 // expected-error {{cannot assign to property}}
321+
a.balboza = 12 // expected-error {{cannot assign through dynamic lookup property: 'a' is a 'let' constant}}
322322
}
323323

324324
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)