summaryrefslogtreecommitdiff
path: root/test/files/run
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-02-01 11:55:01 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-02-01 14:32:20 -0800
commit8ae0e2a37764e0193dccd5658fd35f56edcbfd69 (patch)
treeb6acda3ef9a17f330918a1fdee100f332a86be95 /test/files/run
parent09d143306432124db7b364034abd94792947231e (diff)
downloadscala-8ae0e2a37764e0193dccd5658fd35f56edcbfd69.tar.gz
scala-8ae0e2a37764e0193dccd5658fd35f56edcbfd69.tar.bz2
scala-8ae0e2a37764e0193dccd5658fd35f56edcbfd69.zip
SI-7039 unapplySeq result type independent of subpattern count
Fixes a bug in the implementation of the `unapplySeq` part of the spec below. An `unapply` method with result type `R` in an object `x` matches the pattern `x(p_1, ..., p_n)` if it takes exactly one argument and, either: - `n = 0` and `R =:= Boolean`, or - `n = 1` and `R <:< Option[T]`, for some type `T`. The argument pattern `p1` is typed in turn with expected type `T`. - Or, `n > 1` and `R <:< Option[Product_n[T_1, ..., T_n]]`, for some types `T_1, ..., T_n`. The argument patterns `p_1, ..., p_n` are typed with expected types `T_1, ..., T_n`. An `unapplySeq` method in an object `x` matches the pattern `x(p_1, ..., p_n)` if it takes exactly one argument and its result type is of the form `Option[S]`, where either: - `S` is a subtype of `Seq[U]` for some element type `U`, (set `m = 0`) - or `S` is a `ProductX[T_1, ..., T_m]` and `T_m <: Seq[U]` (`m <= n`). The argument patterns `p_1, ..., p_n` are typed with expected types `T_1, ..., T_m, U, ..., U`. Here, `U` is repeated `n-m` times.
Diffstat (limited to 'test/files/run')
-rw-r--r--test/files/run/t7039.check1
-rw-r--r--test/files/run/t7039.scala11
2 files changed, 12 insertions, 0 deletions
diff --git a/test/files/run/t7039.check b/test/files/run/t7039.check
new file mode 100644
index 0000000000..954906040f
--- /dev/null
+++ b/test/files/run/t7039.check
@@ -0,0 +1 @@
+Matched!
diff --git a/test/files/run/t7039.scala b/test/files/run/t7039.scala
new file mode 100644
index 0000000000..475c4ae267
--- /dev/null
+++ b/test/files/run/t7039.scala
@@ -0,0 +1,11 @@
+object UnapplySeqTest {
+ def unapplySeq(any: Any): Option[(Int, Seq[Int])] = Some((5, List(1)))
+}
+
+object Test extends App {
+ null match {
+ case UnapplySeqTest(5) => println("uh-oh")
+ case UnapplySeqTest(5, 1) => println("Matched!") // compiles
+ case UnapplySeqTest(5, xs @ _*) => println("toooo long: "+ (xs: Seq[Int]))
+ }
+} \ No newline at end of file