Skip to content

[Constraint solver] Reject trailing closures matching non-closure-parameters #24403

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

Conversation

DougGregor
Copy link
Member

Enhance call-argument matching to reject trailing closures that match up
with parameters that cannot accept closures at all.

Fixes rdar://problem/50362170.

…ameters.

Enhance call-argument matching to reject trailing closures that match up
with parameters that cannot accept closures at all.

Fixes rdar://problem/50362170.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor DougGregor merged commit 4e86c8f into swiftlang:master May 1, 2019
@DougGregor DougGregor deleted the constraint-solver-trailing-closure-pruning branch May 1, 2019 13:45

paramTy = paramTy->lookThroughAllOptionalTypes();
return paramTy->isTypeParameter() ||
paramTy->is<ArchetypeType>() ||
Copy link
Contributor

Choose a reason for hiding this comment

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

How precise do you want to get here? If it has any constraints at all, it can't accept a function value (just like non-Any existentials)

// If there is no suitable last parameter to accept the trailing closure,
// notify the listener and bail if we need to.
if (!acceptsTrailingClosure(params[numParams - 1])) {
if (listener.trailingClosureMismatch(numParams - 1, numArgs - 1))
Copy link
Contributor

Choose a reason for hiding this comment

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

In the spirit of matchCallArguments used only to match parameters to arguments based on labels and positions, it seems that better place for this logic could be in other overload of matchCallArguments where types are matched, the problem with that though is that we currently don't diagnose missing parameters via new diagnostic framework, that would have made diagnosing trailing closures much easier...

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