From 16e1b57be1b05c460bbce0de51e607ae6b1b9027 Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Fri, 6 Jul 2007 10:07:15 +0000 Subject: optimzing unapply calls returning Some[T], savi... optimzing unapply calls returning Some[T], saving emptynessCheck fix of #999 (better late than never), added test case to run/unapply.scala --- test/files/run/unapply.scala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test') diff --git a/test/files/run/unapply.scala b/test/files/run/unapply.scala index d351468bec..416f8174f4 100644 --- a/test/files/run/unapply.scala +++ b/test/files/run/unapply.scala @@ -28,6 +28,9 @@ object FaaPrecise { object FaaPreciseSome { def unapply(x: Bar) = Some(x.name) // return type Some[String] } +object VarFoo { + def unapply(a : Int)(implicit b : Int) : Option[Int] = Some(a + b) +} object Foo extends TestCase("Foo") with Assert { def unapply(x: Any): Option[Product2[Int, String]] = x match { case y: Bar => Some(Tuple(y.size, y.name)) @@ -55,6 +58,10 @@ object Foo extends TestCase("Foo") with Assert { assertEquals(doMatch3(b),"medium") assertEquals(doMatch4(b),"medium") assertEquals(doMatch5(b),"medium") + implicit val bc: Int = 3 + assertEquals(4 match { + case VarFoo(x) => x + }, 7) } } @@ -79,11 +86,18 @@ object Mas extends TestCase("Mas") with Assert { } object LisSeqArr extends TestCase("LisSeqArr") with Assert { +// def foo[A](x:List[A]) {} def runTest { assertEquals((List(1,2,3): Any) match { case List(x,y,_*) => (x,y)}, (1,2)) assertEquals((List(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}, (1,2)) assertEquals((Array(1,2,3): Any) match { case Seq(x,y,_*) => (x,y)}, (1,2)) //assertEquals((Array(1,2,3): Any) match { case Array(x,y,_*) => {x,y}}, {1,2}) + + // just compile, feature request #1196 +// (List(1,2,3): Any) match { +// case a @ List(x,y,_*) => foo(a) +// } + } } -- cgit v1.2.3