-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- Error: tests/neg/i18122.scala:10:16 --------------------------------------------------------------------------------- | ||
10 | foo1(y = 1, 2, x = 3) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- Error: tests/neg/i18122.scala:11:16 --------------------------------------------------------------------------------- | ||
11 | foo2(y = 1, 2, x = 3) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- Error: tests/neg/i18122.scala:12:16 --------------------------------------------------------------------------------- | ||
12 | foo1(y = 1, 2, z = 3) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- Error: tests/neg/i18122.scala:13:16 --------------------------------------------------------------------------------- | ||
13 | foo2(y = 1, 2, z = 3) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- Error: tests/neg/i18122.scala:14:16 --------------------------------------------------------------------------------- | ||
14 | foo1(y = 1, 2) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- Error: tests/neg/i18122.scala:15:16 --------------------------------------------------------------------------------- | ||
15 | foo2(y = 1, 2) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- [E171] Type Error: tests/neg/i18122.scala:17:8 ---------------------------------------------------------------------- | ||
17 | bar1() // error: missing arg | ||
| ^^^^^^ | ||
| missing argument for parameter x of method bar1 in object Test: (x: Int, ys: Int*): Unit | ||
-- [E171] Type Error: tests/neg/i18122.scala:23:8 ---------------------------------------------------------------------- | ||
23 | bar1(ys = 1) // error: missing arg | ||
| ^^^^^^^^^^^^ | ||
| missing argument for parameter x of method bar1 in object Test: (x: Int, ys: Int*): Unit | ||
-- Error: tests/neg/i18122.scala:43:16 --------------------------------------------------------------------------------- | ||
43 | bar1(x = 1, 2, ys = 3) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- Error: tests/neg/i18122.scala:44:18 --------------------------------------------------------------------------------- | ||
44 | bar1(1, 2, ys = 3) // error: parameter ys is already instantiated | ||
| ^^^^^^ | ||
| parameter ys of method bar1 in object Test: (x: Int, ys: Int*): Unit is already instantiated | ||
-- Error: tests/neg/i18122.scala:45:16 --------------------------------------------------------------------------------- | ||
45 | bar2(x = 1, 2, ys = 3) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- Error: tests/neg/i18122.scala:46:17 --------------------------------------------------------------------------------- | ||
46 | bar1(ys = 1, 2, x = 3) // error: positional after named | ||
| ^ | ||
| positional after named argument | ||
-- Error: tests/neg/i18122.scala:47:17 --------------------------------------------------------------------------------- | ||
47 | bar2(ys = 1, 2, x = 3) // error: positional after named | ||
| ^ | ||
| positional after named argument |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
object Test { | ||
def foo1(x: Int, y: Int, z: Int) = println((x, y, z)) | ||
def foo2(x: Int = 0, y: Int, z: Int) = println((x, y, z)) | ||
def bar1(x: Int, ys: Int*) = println((x, ys)) | ||
def bar2(x: Int = 0, ys: Int*) = println((x, ys)) | ||
|
||
def main(args: Array[String]) = { | ||
foo1(1, y = 2, 3) | ||
foo2(1, y = 2, 3) | ||
foo1(y = 1, 2, x = 3) // error: positional after named | ||
foo2(y = 1, 2, x = 3) // error: positional after named | ||
foo1(y = 1, 2, z = 3) // error: positional after named | ||
foo2(y = 1, 2, z = 3) // error: positional after named | ||
foo1(y = 1, 2) // error: positional after named | ||
foo2(y = 1, 2) // error: positional after named | ||
|
||
bar1() // error: missing arg | ||
bar2() | ||
bar1(1) | ||
bar2(1) | ||
bar1(x = 1) | ||
bar2(x = 1) | ||
bar1(ys = 1) // error: missing arg | ||
bar2(ys = 1) | ||
bar1(1, 2) | ||
bar2(1, 2) | ||
bar1(1, ys = 2) | ||
bar2(1, ys = 2) | ||
bar1(x = 1, 2) | ||
bar2(x = 1, 2) | ||
bar1(x = 1, ys = 2) | ||
bar2(x = 1, ys = 2) | ||
bar1(ys = 1, x = 2) | ||
bar2(ys = 1, x = 2) | ||
bar1(1, 2, 3) | ||
bar2(1, 2, 3) | ||
bar1(1, ys = 2, 3) | ||
bar2(1, ys = 2, 3) | ||
bar1(x = 1, 2, 3) | ||
bar2(x = 1, 2, 3) | ||
bar1(x = 1, ys = 2, 3) | ||
bar2(x = 1, ys = 2, 3) | ||
bar1(x = 1, 2, ys = 3) // error: positional after named | ||
bar1(1, 2, ys = 3) // error: parameter ys is already instantiated | ||
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 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)
? probablyparameter 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 arg2
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.