From 8ae0e2a37764e0193dccd5658fd35f56edcbfd69 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Fri, 1 Feb 2013 11:55:01 -0800 Subject: 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. --- test/files/run/t7039.check | 1 + test/files/run/t7039.scala | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/files/run/t7039.check create mode 100644 test/files/run/t7039.scala (limited to 'test/files/run') 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 -- cgit v1.2.3