From 2ec348815b8b39be06ee09481cc6eb3531a8af51 Mon Sep 17 00:00:00 2001 From: Burak Emir Date: Mon, 18 Jun 2007 13:40:24 +0000 Subject: added setting Xmatchalgo + cleanup of PatternMa... added setting Xmatchalgo + cleanup of PatternMatchers * more control on which algo get used * removed some obsolete code * added test case --- test/files/run/patmatnew.scala | 51 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'test/files') diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala index f8216177cd..0e7359a2b8 100644 --- a/test/files/run/patmatnew.scala +++ b/test/files/run/patmatnew.scala @@ -22,10 +22,10 @@ object Test extends TestConsoleMain { new Test717, new TestGuards, new TestStream, + new Test903, new Test1163_Order ) - class Foo(j:Int) { case class Bar(i:Int) } @@ -122,8 +122,52 @@ object Test extends TestConsoleMain { trait NodeImpl; trait IfImpl; private def coerceIf(node : Node) = node match { - case node : IfImpl => node; // var node is of type Node with IfImpl! - case _ => null; + case node : IfImpl => node; // var node is of type Node with IfImpl! + case _ => null; + } + } + } + + + class Person(_name : String, _father : Person) { + def name = _name + def father = _father + } + + object PersonFather { + def unapply(p : Person) : Option[Person] = + if (p.father == null) + None + else + Some(p.father) + } + + class Test903 extends TestCase("bug903") { + + override def runTest = { + val p1 = new Person("p1",null) + val p2 = new Person("p2",p1) + assertEquals((p2.name, p1.name), p2 match { + case aPerson@PersonFather(f) => (aPerson.name,f.name) + case _ => "No father" + }) + } + } + + + object Foo1 { + class Bar1(val x : String) + def p(b : Bar1) = Console.println(b.x) + + def unapply(s : String) : Option[Bar1] = + Some(new Bar1(s)) + } + + object bug881 extends TestCase("881") { + override def runTest = { + "baz" match { + case Foo1(x) => + Foo1.p(x) } } } @@ -178,5 +222,6 @@ object Test extends TestConsoleMain { def lala() = 42 match { case FooBar => true } + } -- cgit v1.2.3