From 2bc40d593a84a510ccf18b1666a419f77665fcb4 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 11 Jul 2009 05:02:16 +0000 Subject: Fix and test case for #1260. --- .../scala/tools/nsc/matching/ParallelMatching.scala | 10 ++++++---- test/files/pos/t1260.scala | 18 ++++++++++++++++++ test/pending/pos/t1260.scala | 17 ----------------- 3 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 test/files/pos/t1260.scala delete mode 100644 test/pending/pos/t1260.scala diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index c79385488a..ecf3dddfea 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -983,10 +983,12 @@ trait ParallelMatching extends ast.TreeDSL { val fail = frep map (_.toTree) getOrElse (failTree) // dig out case field accessors that were buried in (***) - val cfa = if (pats.isCaseHead) casted.accessors else Nil - val caseTemps = srep.tvars match { case x :: xs if x == casted.sym => xs ; case x => x } - def needCast = if (casted.sym ne scrut.sym) List(VAL(casted.sym) === (scrut.id AS_ANY castedTpe)) else Nil - val vdefs = needCast ::: ( + val cfa = if (pats.isCaseHead) casted.accessors else Nil + val caseTemps = srep.tvars match { case x :: xs if x == casted.sym => xs ; case x => x } + def castedScrut = typedValDef(casted.sym, scrut.id AS castedTpe) + def needCast = if (casted.sym ne scrut.sym) List(castedScrut) else Nil + + val vdefs = needCast ::: ( for ((tmp, accessor) <- caseTemps zip cfa) yield typedValDef(tmp, typer typed fn(casted.id, accessor)) ) diff --git a/test/files/pos/t1260.scala b/test/files/pos/t1260.scala new file mode 100644 index 0000000000..9cd860afd8 --- /dev/null +++ b/test/files/pos/t1260.scala @@ -0,0 +1,18 @@ +case class Foo(a: String, b: String) + +object Bar { + def unapply(s: String): Option[Long] = + try { Some(s.toLong) } catch { case _ => None } +} + +object Test { + def main(args: Array[String]) { + val f = Foo("1", "2") + f match { + case Foo(Bar(1), Bar(2)) => 1 + case Foo(Bar(i), Bar(j)) if i >= 0 => 2 + case _ => 3 + } + } +} + diff --git a/test/pending/pos/t1260.scala b/test/pending/pos/t1260.scala deleted file mode 100644 index b05259998e..0000000000 --- a/test/pending/pos/t1260.scala +++ /dev/null @@ -1,17 +0,0 @@ -case class Foo(a: String, b: String) - -object Bar { - def unapply(s: String): Option[Long] = - try { Some(s.toLong) } catch { case _ => None } -} - -object Test { - def main(args: Array[String]) { - val f = Foo("1", "2") - f match { - case Foo(Bar(1), Bar(2)) => () - case Foo(Bar(i), Bar(j)) if i >= 0 => () - } - } -} - -- cgit v1.2.3