-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #8715: enforce syntax for _* #8732
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1531f3
Fix #8715: enforce syntax for _*
liufengyun f4728d7
Add test
liufengyun 3340669
Handle usage of _* in expressions
liufengyun d67fcc1
Fix CI: adapt test
liufengyun 2ffdad5
Print lines instead of pos in test
liufengyun a986d22
Fix CI: support _* used in infix parenthesis
liufengyun ecf8510
Update community build
liufengyun 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
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 |
---|---|---|
@@ -1,18 +1,18 @@ | ||
object O { | ||
def m1(a: Int*) = (a: _*) // error: Cannot return repeated parameter type Int* | ||
def m1(a: Int*) = (a: _*) // error // error: Cannot return repeated parameter type Int* | ||
def m2(a: Int*) = { // error: Cannot return repeated parameter type Int* | ||
val b = (a: _*) // error: Cannot return repeated parameter type Int* | ||
val b = (a: _*) // error // error: Cannot return repeated parameter type Int* | ||
b | ||
} | ||
def m3(a: Int*): Any = { | ||
val b = (a: _*) // error: Cannot return repeated parameter type Int* | ||
val b = (a: _*) // error // error: Cannot return repeated parameter type Int* | ||
b | ||
} | ||
def m4(a: 2*) = (a: _*) // error: Cannot return repeated parameter type Int* | ||
def m4(a: 2*) = (a: _*) // error // error: Cannot return repeated parameter type Int* | ||
|
||
} | ||
|
||
class O(a: Int*) { | ||
val m = (a: _*) // error: Cannot return repeated parameter type Int* | ||
val m = (a: _*) // error // error: Cannot return repeated parameter type Int* | ||
} | ||
|
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,2 @@ | ||
@main | ||
def Test = List(42) match { case List(xs @ (ys: _*)) => xs } // error |
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,29 @@ | ||
|
||
object Test { | ||
case class K(i: Int) | ||
|
||
def main(args: Array[String]) = { | ||
val k = new K(9) | ||
val is = List(1,2,3) | ||
|
||
is match { | ||
case List(1, _*,) => // error // error // error: bad use of _* (a sequence pattern must be the last pattern) | ||
// illegal start of simple pattern | ||
case List(1, _*3,) => // error // error: illegal start of simple pattern | ||
//case List(1, _*3:) => // poor recovery by parens | ||
case List(1, x*) => // error: use _* to match a sequence | ||
case List(x*, 1) => // error: trailing * is not a valid pattern | ||
case (1, x*) => // error: trailing * is not a valid pattern | ||
case (1, x@_*) => // error: bad use of _* (sequence pattern not allowed) | ||
} | ||
|
||
// good syntax, bad semantics, detected by typer | ||
//gowild.scala:14: error: star patterns must correspond with varargs parameters | ||
val K(x @ _*) = k | ||
val K(ns @ _*, x) = k // error: bad use of _* (a sequence pattern must be the last pattern) | ||
val (b, _ * ) = (5,6) // error: bad use of _* (sequence pattern not allowed) | ||
// no longer complains | ||
//bad-and-wild.scala:15: error: ')' expected but '}' found. | ||
} | ||
} | ||
|
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,4 @@ | ||
// from stdlib | ||
class Test { | ||
def printf(text: String, args: Any*): Unit = { System.out.print(text format (args : _*)) } | ||
} |
This file was deleted.
Oops, something went wrong.
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.
Maybe be more aggressive and demand this for 3.0? In any case, we should do migration warning and it would be nice to also offer a rewrite.
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.
In fact, I believe the warning that this is no longer supported is more important than the error that it's in the wrong place. The theory is that any code that has
xs @ _*
will have already been compiled by Scala 2 (in most cases, at least)