Skip to content

[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter #29845

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
Feb 16, 2020

Conversation

omochi
Copy link
Contributor

@omochi omochi commented Feb 14, 2020

This patch improve trailing closure matching with parameters.

Currently, trailing closure can match with function parameter followed by one defaulted parameter.
But it can not do if:

  • function type from generic parameter.
  • More than one defaulted parameters exist.

For example with below,

  func foo<T>(fn: () -> T, value: Int = 0) {}
  foo { 42 }

  func bar<T>(type: T.Type, fn: T, a: Int = 0) {}
  bar(type: (() -> Int).self) { 42 }

  func baz(fn: () -> Int, a: Int = 0, b: Int = 0, c: Int = 0) {}
  baz { 42 }

Only foo is ok but bar and baz are rejected.

This patch supports all of them.

@xedin Please review it.

@theblixguy theblixguy requested a review from xedin February 14, 2020 17:21
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution, @omochi! Changes make sense to me, I think we just need to tweak the iteration a bit and should be good to go.

@omochi omochi force-pushed the trailing-closure-position branch from db992a3 to d4eea5a Compare February 15, 2020 06:43
@omochi
Copy link
Contributor Author

omochi commented Feb 15, 2020

@xedin I modified to decrement loop.
As unsigned can not use x >= 0, I put exit branching at end of loop.

In this project, counter variable seems to be often unsigned.
Or should I use int as counter variable?

@omochi omochi force-pushed the trailing-closure-position branch from d4eea5a to 62dd7f6 Compare February 15, 2020 22:41
@omochi
Copy link
Contributor Author

omochi commented Feb 15, 2020

I pushed third trial.
I am testing locally now.

defaulted parameters are after last function parameter
@omochi omochi force-pushed the trailing-closure-position branch from 62dd7f6 to 252e82f Compare February 15, 2020 22:48
@xedin
Copy link
Contributor

xedin commented Feb 15, 2020

Looks good, let’s run the CI

@xedin
Copy link
Contributor

xedin commented Feb 15, 2020

@swift-ci please smoke test

@xedin
Copy link
Contributor

xedin commented Feb 15, 2020

@swift-ci please test source compatibility

@xedin
Copy link
Contributor

xedin commented Feb 16, 2020

SwiftNIO failures are unrelated, let get this merged. Thank you, again!

@xedin xedin merged commit 4b2b436 into swiftlang:master Feb 16, 2020
@omochi omochi deleted the trailing-closure-position branch February 16, 2020 09:07
@omochi
Copy link
Contributor Author

omochi commented Feb 16, 2020

Thanks!!

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.

2 participants