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
[SE-0284] Allow Multiple Variadic Parameters in Functions, Subscripts, and Initializers #29735
Conversation
Oops, I meant to submit this as a draft |
Nice. Does this SILGen and run properly as well? |
@theblixguy yep, although I need to write some tests for it at some point :). Everything just gets passed around in Arrays so having 2+ hasn’t been a problem. |
068ded7
to
baa4333
Compare
baa4333
to
5d30379
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
That’s odd, I’m seeing some unexpected passes on the source compatibility suite... |
5d30379
to
fe2c00c
Compare
Let's see if we might be able to get away with making the following declarations an error: subscript(a: Int..., b: Int)
let closure = {(a: Int..., b: Int) in} These are allowed today because of a bug, but there's no way to successfully call them. It's also possible to write: subscript(a: Int..., b: Int = 1) which can be called (but If the source break is too large, I'll probably try to make these at least a warning as part of the proposal. |
@swift-ci please test |
@swift-ci please test source compatibility |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Looks like |
@swift-ci please test |
@swift-ci please test source compatibility |
Build failed |
@swift-ci please test Linux |
c0d931a
to
a83f19b
Compare
rebasing on recent changes @swift-ci please test |
@swift-ci please test source compatibility |
Build failed |
@swift-ci test |
@swift-ci test source compatibility |
@swift-ci please test Linux |
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.
Parser changes looks great 👍
Could you add some test cases in test/Syntax/round_trip_parse_gen.swift
?
let closure2 = {(x: Int..., y: Int) in } // expected-error {{no parameters may follow a variadic parameter in a closure}} | ||
let closure3 = {(x: Int..., y: Int, z: Int...) in } // expected-error {{no parameters may follow a variadic parameter in a closure}} | ||
let closure4 = {(x: Int...) in } | ||
let closure5 = {(x: Int, y: Int...) in } |
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.
I guess {(x: Int..., y z: Int) in }
is still diagnosed as error: closure cannot have keyword arguments
, but it should be error: no parameters may follow a variadic parameter in a closure
because removing the argument label doesn't resolve the issue.
It would be great if we can improve this. (not in this PR)
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.
I added a test case for this, right now both diagnostics are emitted.
@swift-ci smoke test |
@swift-ci Please smoke test macOS |
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.
Parser change looks good.
@swift-ci Please smoke test macOS |
@swift-ci please test Windows platform |
[SE-0284] Add round_trip_parse_gen tests [SE-0284] Add missing test cases
c8382ec
to
9708247
Compare
@swift-ci test |
I added a couple more argument matching tests for forward matching of multiple trailing closures + multiple varargs now that SE-286 is implemented. @xedin do you mind reviewing the argument matching test cases before this is merged? There aren't any code changes to argument matching, but I want to make sure I haven't missed any newly introduced edge cases |
@owenv Sure, I'll take a look as soon as possible! |
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.
Tests look reasonable to me!
Rerunning tests before I merge this since the master-rebranch merge happened recently @swift-ci test |
@swift-ci please test source compatibility |
Build failed |
@swift-ci please test Linux platform |
Looks like the debug source compatibility failures (BlueSocket and ReactiveCocoa) are also happening in all other PRs from the past few days, so unrelated to this change. |
@owenv Thank you! Could you update |
The restriction that the argument following a variadic argument must have a label is still in place. This allows the following:
Because varargs get automatic default expressions of
[]
, the following is also allowed right now, and maybe shouldn't be:The alternative is to just require every vararg have a label if there's more than one, which won't be difficult to enforce if that ends up being preferable.