Skip to content

Commit cd4909b

Browse files
authored
Merge pull request #18640 from xedin/improve-simplify-locator
[Diagnostics] Improve `simplifyLocator` to extract arguments from unr…
2 parents ba965ec + 538e5e8 commit cd4909b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void constraints::simplifyLocator(Expr *&anchor,
147147

148148
while (!path.empty()) {
149149
switch (path[0].getKind()) {
150-
case ConstraintLocator::ApplyArgument:
150+
case ConstraintLocator::ApplyArgument: {
151151
// Extract application argument.
152152
if (auto applyExpr = dyn_cast<ApplyExpr>(anchor)) {
153153
// The target anchor is the function being called.
@@ -167,7 +167,20 @@ void constraints::simplifyLocator(Expr *&anchor,
167167
path = path.slice(1);
168168
continue;
169169
}
170+
171+
if (auto *UME = dyn_cast<UnresolvedMemberExpr>(anchor)) {
172+
// The target anchor is the method being called,
173+
// no additional information could be retrieved
174+
// about this call.
175+
targetAnchor = nullptr;
176+
targetPath.clear();
177+
178+
anchor = UME->getArgument();
179+
path = path.slice(1);
180+
continue;
181+
}
170182
break;
183+
}
171184

172185
case ConstraintLocator::ApplyFunction:
173186
// Extract application function.
@@ -317,7 +330,7 @@ void constraints::simplifyLocator(Expr *&anchor,
317330
// This was just for identifying purposes, strip it off.
318331
path = path.slice(1);
319332
continue;
320-
333+
321334
default:
322335
// FIXME: Lots of other cases to handle.
323336
break;

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ let _: Color = .overload(1) // expected-error {{ambiguous reference to member '
447447
let _: Color = .frob(1.0, &i) // expected-error {{missing argument label 'b:' in call}}
448448
let _: Color = .frob(1.0, b: &i) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
449449
let _: Color = .frob(1, i) // expected-error {{missing argument label 'b:' in call}}
450-
let _: Color = .frob(1, b: i) // expected-error {{passing value of type 'Int' to an inout parameter requires explicit '&'}}
450+
let _: Color = .frob(1, b: i) // expected-error {{passing value of type 'Int' to an inout parameter requires explicit '&'}} {{28-28=&}}
451451
let _: Color = .frob(1, &d) // expected-error {{missing argument label 'b:' in call}}
452452
let _: Color = .frob(1, b: &d) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
453453
var someColor : Color = .red // expected-error {{enum type 'Color' has no case 'red'; did you mean 'Red'}}

0 commit comments

Comments
 (0)