summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Unapplies.scala5
-rw-r--r--test/files/run/virtpatmat_extends_product.check1
-rw-r--r--test/files/run/virtpatmat_extends_product.flags1
-rw-r--r--test/files/run/virtpatmat_extends_product.scala11
4 files changed, 18 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
index cc272b7b8d..4f5b6868ae 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Unapplies.scala
@@ -45,6 +45,11 @@ trait Unapplies extends ast.TreeDSL
case BooleanClass => Nil
case OptionClass | SomeClass =>
val prod = tp.typeArgs.head
+// the spec doesn't allow just any subtype of Product, it *must* be TupleN[...] -- see run/virtpatmat_extends_product.scala
+// this breaks plenty of stuff, though...
+// val targs =
+// if (isTupleType(prod)) getProductArgs(prod)
+// else List(prod)
val targs = getProductArgs(prod)
if (targs.isEmpty || targs.tail.isEmpty) List(prod) // special n == 0 || n == 1
diff --git a/test/files/run/virtpatmat_extends_product.check b/test/files/run/virtpatmat_extends_product.check
new file mode 100644
index 0000000000..c07e8385a7
--- /dev/null
+++ b/test/files/run/virtpatmat_extends_product.check
@@ -0,0 +1 @@
+AnnotationInfo(a,1)
diff --git a/test/files/run/virtpatmat_extends_product.flags b/test/files/run/virtpatmat_extends_product.flags
new file mode 100644
index 0000000000..ac6b805bd0
--- /dev/null
+++ b/test/files/run/virtpatmat_extends_product.flags
@@ -0,0 +1 @@
+-Yvirtpatmat
diff --git a/test/files/run/virtpatmat_extends_product.scala b/test/files/run/virtpatmat_extends_product.scala
new file mode 100644
index 0000000000..e564f4430b
--- /dev/null
+++ b/test/files/run/virtpatmat_extends_product.scala
@@ -0,0 +1,11 @@
+object Test extends App {
+ case class AnnotationInfo(a: String, b: Int) extends Product2[String, Int]
+
+ // if we're not careful in unapplyTypeListFromReturnType, the generated unapply is
+ // thought to return two components instead of one, since AnnotationInfo (the result of the unapply) is a Product2
+ case class NestedAnnotArg(ai: AnnotationInfo)
+
+ NestedAnnotArg(AnnotationInfo("a", 1)) match {
+ case NestedAnnotArg(x) => println(x)
+ }
+} \ No newline at end of file