Skip to content

[Diagnostics] Improve simplifyLocator to extract arguments from unr… #18640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2018
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
17 changes: 15 additions & 2 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void constraints::simplifyLocator(Expr *&anchor,

while (!path.empty()) {
switch (path[0].getKind()) {
case ConstraintLocator::ApplyArgument:
case ConstraintLocator::ApplyArgument: {
// Extract application argument.
if (auto applyExpr = dyn_cast<ApplyExpr>(anchor)) {
// The target anchor is the function being called.
Expand All @@ -167,7 +167,20 @@ void constraints::simplifyLocator(Expr *&anchor,
path = path.slice(1);
continue;
}

if (auto *UME = dyn_cast<UnresolvedMemberExpr>(anchor)) {
// The target anchor is the method being called,
// no additional information could be retrieved
// about this call.
targetAnchor = nullptr;
targetPath.clear();

anchor = UME->getArgument();
path = path.slice(1);
continue;
}
break;
}

case ConstraintLocator::ApplyFunction:
// Extract application function.
Expand Down Expand Up @@ -317,7 +330,7 @@ void constraints::simplifyLocator(Expr *&anchor,
// This was just for identifying purposes, strip it off.
path = path.slice(1);
continue;

default:
// FIXME: Lots of other cases to handle.
break;
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ let _: Color = .overload(1) // expected-error {{ambiguous reference to member '
let _: Color = .frob(1.0, &i) // expected-error {{missing argument label 'b:' in call}}
let _: Color = .frob(1.0, b: &i) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
let _: Color = .frob(1, i) // expected-error {{missing argument label 'b:' in call}}
let _: Color = .frob(1, b: i) // expected-error {{passing value of type 'Int' to an inout parameter requires explicit '&'}}
let _: Color = .frob(1, b: i) // expected-error {{passing value of type 'Int' to an inout parameter requires explicit '&'}} {{28-28=&}}
let _: Color = .frob(1, &d) // expected-error {{missing argument label 'b:' in call}}
let _: Color = .frob(1, b: &d) // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
var someColor : Color = .red // expected-error {{enum type 'Color' has no case 'red'; did you mean 'Red'}}
Expand Down