diff options
author | Som Snytt <som.snytt@gmail.com> | 2012-04-22 02:58:26 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2012-04-26 11:44:39 -0700 |
commit | 9d925a30c73ee5856c83d3caab124f7dbeaa85a8 (patch) | |
tree | d7a14c7d0466435523452ed2cc88fe3d82c9e9b6 /test/files/neg/t5702-neg-bad-and-wild.scala | |
parent | 3c9c18ddccc17c2b0e62195315ba2abb72d3b761 (diff) | |
download | scala-9d925a30c73ee5856c83d3caab124f7dbeaa85a8.tar.gz scala-9d925a30c73ee5856c83d3caab124f7dbeaa85a8.tar.bz2 scala-9d925a30c73ee5856c83d3caab124f7dbeaa85a8.zip |
SI-5702 Pattern parser halts on star
In patterns, the parser halts when it sees stars.
This means it does not handle infix notation for a case class
named "*". This patch uses lookahead to decide whether to parse
'_' '*' as a sequence pattern or as the start of infix.
(For both normal and error cases, the tokens are always consumed
immediately.) Error messages are improved for _* (as a help to learners)
and slightly improved recovery helps the parse continue.
The entry point for XML patterns is now distinct; otherwise,
the change is local to pattern3-simplepattern; the entry point
for simplepattern() is unchanged because it is commented
"hook for IDE."
Diffstat (limited to 'test/files/neg/t5702-neg-bad-and-wild.scala')
-rw-r--r-- | test/files/neg/t5702-neg-bad-and-wild.scala | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/files/neg/t5702-neg-bad-and-wild.scala b/test/files/neg/t5702-neg-bad-and-wild.scala new file mode 100644 index 0000000000..3833a002b1 --- /dev/null +++ b/test/files/neg/t5702-neg-bad-and-wild.scala @@ -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, _*,) => // bad use of _* (a sequence pattern must be the last pattern) + // illegal start of simple pattern + case List(1, _*3,) => // illegal start of simple pattern + //case List(1, _*3:) => // poor recovery by parens + case List(1, x*) => // use _* to match a sequence + case List(x*, 1) => // trailing * is not a valid pattern + case (1, x*) => // trailing * is not a valid pattern + case (1, x@_*) => // 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(is @ _*) = k + val K(ns @ _*, x) = k // bad use of _* (a sequence pattern must be the last pattern) + val (b, _ * ) = Pair(5,6) // bad use of _* (sequence pattern not allowed) +// no longer complains +//bad-and-wild.scala:15: error: ')' expected but '}' found. + } +} + |