-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add an educational note explaining SE-0286 changes #33119
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
|
||
In Swift, calling a function with one or more trailing closure arguments requires the label of the first trailing closure argument to be omitted. As a result, the compiler must consider additional context when determining which function parameter the trailing closure should satisfy. | ||
|
||
Before Swift 5.3, the compiler used a backward scanning rule to match a trailing closure to a function parameter. Starting from the end of the parameter list, it moved backwards until finding a parameter compatible with trailing closures. This could sometimes lead to unexpected behavior. Consider the following example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explanation is a little vague, but I think that's OK since it describes the old behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace compatible with trailing closures
with which could accept a trailing closure argument i.e. function type, generic parameter, 'Any' type
?
Thanks @benrimmington! |
5d79f83
to
cee71ae
Compare
This comment has been minimized.
This comment has been minimized.
|
||
In Swift, calling a function with one or more trailing closure arguments requires the label of the first trailing closure argument to be omitted. As a result, the compiler must consider additional context when determining which function parameter the trailing closure should satisfy. | ||
|
||
Before Swift 5.3, the compiler used a backward scanning rule to match a trailing closure to a function parameter. Starting from the end of the parameter list, it moved backwards until finding a parameter compatible with trailing closures. This could sometimes lead to unexpected behavior. Consider the following example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe replace compatible with trailing closures
with which could accept a trailing closure argument i.e. function type, generic parameter, 'Any' type
?
Apply suggestions from code review Co-authored-by: Ben Rimmington <[email protected]> Reword explanation of pre-5.3 behavior Associate SE-0286 note with warning diagnostic
a017a58
to
bacc96b
Compare
@swift-ci smoke test |
Some of this is copied verbatim from the proposal, but IMO it's important to have some documentation of this change beyond the SE proposal to communicate the expected impact.
If and when SE-0286 is accepted, I'll associate this note with whatever the final set of diagnostics is and hopefully cherrypick to the 5.3 branch.