-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Unnamed parameters after named ones #18122
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
Comments
@odersky what behaviour would you expect here? |
I think Scala 2's behavior is reasonable here. Except I think it's OK to accept |
The Urtext comment on Scala 2:
Recalling that named args can be merely documentary: Then perhaps Then In particular, I was considering tweaking applications for Scala 2, so if I do that and any changes are made here, I will try to align with them. |
Issue "positional after named argument" errors if a positional argument follows a named argument and one of the following is true: - There is a formal argument before the argument position that has not yet been instantiated with a previous actual argument, (either named or positional), or - The formal parameter at the argument position is also mentioned in a subsequent named parameter. This brings the behavior largely in line with Scala 2. Fixes #18122
Compiler version
3.3.2-RC1-bin-20230630-c629090-NIGHTLY and before
Minimized code
The following snippet contains multiple cases obtained by uncommenting one of the commented lines at a time.
Output
Abbreviated error messages explained:
positional after named
-positional after named argument
(scala 2)too many arguments
-too many arguments for method ...
missing argument x
-missing argument for parameter x of method ...
(scala 3),not enough arguments for method ... Unspecified value parameter x
(scala 2)def bar2 not compiling
-a parameter section with a `*`-parameter is not allowed to have default arguments
(scala 2)vararg required exactly once
-when using named arguments, the vararg parameter has to be specified exactly once
Expectation
foo1(y = 1, 2, x = 3)
into account)ys = Seq(2, 3)
instead ofys = 2, 3
, but this doesn't work. Should any of these syntaxes be legal at all? Especially the results forbar2(ys = 2, 3)
andbar2(x = 1, 2, ys = 3)
seem very confusing to mefoo1(y = 1, 2, z = 3)
,foo2(y = 1, 2, z = 3)
,foo1(y = 1, 2)
andbar1(ys = 2, 3)
should be improved - currently it's not clear if the fix would be to add a name to an unnamed argument or to add another (possibly unnamed) argumentThe text was updated successfully, but these errors were encountered: