-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #8715: enforce syntax for _* (alternate version)
Previously we didn't check that _* is indeed the last argument, checking for ")" is not enough, as ")" may be the closing parenthesis of a nested pattern.
- Loading branch information
Showing
8 changed files
with
88 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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.