File: t5702-neg-bad-and-wild.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (29 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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, _ * ) = (5,6) // bad use of _* (sequence pattern not allowed)
// no longer complains
//bad-and-wild.scala:15: error: ')' expected but '}' found.
  }
}