-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Issue "positional after named argument" errors #18363
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
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
bar2(x = 1, 2, ys = 3) // error: positional after named | ||
bar1(ys = 1, 2, x = 3) // error: positional after named | ||
bar2(ys = 1, 2, x = 3) // error: positional after named | ||
} |
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.
bar2(x = 1, ys = 2, ys = 3)
? probably parameter ys is already instantiated
.
bar2(x = 1, 2, ys = 3) // error: positional after named
on L45 is slightly confusing message.
I expect that if named args do not change ordering, then it's always OK.
I see the rule that's being enforced is that ys
always names the start of the repeated param. Then the positional arg 2
is unknown detritus.
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.
All true, but positional after named is technically correct, and it would be messy to change the logic to emit a different error message. Keeping logic clean in the compiler is an underestimated good. Lose it and you enter quickly a downward slide where in the end nobody understands the code anymore.
@som-snytt any further objections or can we get this merged? |
LGTM! I especially appreciate
It's easy to go overboard, and the voice of experience is also an underestimated good. I haven't looked at Scala 2 messaging yet, which I will do in light of:
|
There are 3 OpenCB projects which are now failing after this change, but I would not say it's an regression, but rather an improvement.
My question is, @Kordyjan should we backport this change to Scala 3.3.x? case class Foo(a: Int, b: Long, c: Int){
def x = copy(b = 0L, 0) // is the second param targetting `a` or `c`?
} |
The previous (interesting) expectation was that a named arg "resets" the position, such that defaults to the left of that position are supplied. (Such as on zio-arangodb.)
which on 3.3.0
my dotty just finished compiling, so for completeness
The wrong expectation is not terrible, because visually you align the named arg with the signature. It feels like a feature, because otherwise default args are convenient only in trailing position. The case class copy example is deceptive because there is no signature to look at besides the class parameters. (You don't see the defaults, in other words.) The argument for backporting is that it's never too early to correct a mistaken expectation. |
Issue "positional after named argument" errors if a positional argument follows a named argument and one of the following is true:
This brings the behavior largely in line with Scala 2.
Fixes #18122