summaryrefslogtreecommitdiff
path: root/test/files/run/unapply.scala
diff options
context:
space:
mode:
authorBurak Emir <emir@epfl.ch>2007-07-06 10:07:15 +0000
committerBurak Emir <emir@epfl.ch>2007-07-06 10:07:15 +0000
commit16e1b57be1b05c460bbce0de51e607ae6b1b9027 (patch)
treea34641b84da4ad568221f9aaeec869eeff105ce6 /test/files/run/unapply.scala
parent0cd9d0935523dc7176d2b3bfab3ca7e46aa99af0 (diff)
downloadscala-16e1b57be1b05c460bbce0de51e607ae6b1b9027.tar.gz
scala-16e1b57be1b05c460bbce0de51e607ae6b1b9027.tar.bz2
scala-16e1b57be1b05c460bbce0de51e607ae6b1b9027.zip
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
Diffstat (limited to 'test/files/run/unapply.scala')
-rw-r--r--test/files/run/unapply.scala14
1 files changed, 14 insertions, 0 deletions
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)
+// }
+
}
}