Skip to content

[ConstraintSystem] Start to allow diagnosing ambiguity with fixes for solution sets with more than one fix. #28979

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
Jan 3, 2020

Conversation

hborla
Copy link
Member

@hborla hborla commented Jan 2, 2020

For now, we only do this for for ambiguous function calls that only have argument mismatches in the solutions. All fixes still must have the same callee locator.

@hborla hborla requested a review from xedin January 2, 2020 18:45
@hborla
Copy link
Member Author

hborla commented Jan 2, 2020

@swift-ci please smoke test

auto overload = viable->getOverloadChoice(commonCalleeLocator);
auto *fn = overload.openedType->getAs<AnyFunctionType>();
assert(fn);
DE.diagnose(overload.choice.getDecl()->getLoc(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question, I wonder if with this we might be able to get rid of the wrong_argument_labels_overload in CSDiag here? I'm asking because I was looking into this just yesterday :))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does cover ambiguity due to argument label mismatches so it's very possible that wrong_argument_labels_overload in CSDiag is obsolete. I'm testing it now!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be obsolete - thanks for catching this!

return false;

const auto *fix = fixes.front();
auto *locator = fix->getLocator();
if (ambiguityKind == AmbiguityKind::CloseMatch && fixes.size() > 1)
Copy link
Contributor

@xedin xedin Jan 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this condition:

if (fixes.size() > 1) {
  ambiguityKind = (ambiguityKind == AmbiguityKind::CloseMatch || 
                   ambiguityKind == AmbiguityKind::ParameterList) &&
  llvm::all_of(fixes, [](const ConstraintFix *fix) -> bool {
    auto *locator = fix->getLocator();
    return locator->findLast<LocatorPathElt::ApplyArgument>();
  }) ? AmbiguityKind::ParameterList 
     : AmbiguityKind::General;
}

I think it's okay to check for the common locator as a separate pass to keep this simple since it's not that performance sensitive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think it's better to determine the ambiguity kind separately, thanks! I'll make this change

@hborla hborla force-pushed the ambiguous-call-diagnostics branch from 04da66f to 221cdce Compare January 3, 2020 07:24
@hborla hborla force-pushed the ambiguous-call-diagnostics branch from 221cdce to 9e73bb3 Compare January 3, 2020 07:48
@hborla
Copy link
Member Author

hborla commented Jan 3, 2020

@swift-ci please smoke test

@hborla hborla merged commit 475b559 into swiftlang:master Jan 3, 2020
@hborla hborla deleted the ambiguous-call-diagnostics branch January 3, 2020 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants