diff options
author | Burak Emir <emir@epfl.ch> | 2007-09-01 06:51:58 +0000 |
---|---|---|
committer | Burak Emir <emir@epfl.ch> | 2007-09-01 06:51:58 +0000 |
commit | 8af1dfade7e0fafcbe7adb4dbea14d734d9b8dea (patch) | |
tree | 3ec75d2046cb589b9c7d4d0ae4bffa27f1159b26 | |
parent | 77de72ce86f2fd83c646cfc1c5fd21de26318477 (diff) | |
download | scala-8af1dfade7e0fafcbe7adb4dbea14d734d9b8dea.tar.gz scala-8af1dfade7e0fafcbe7adb4dbea14d734d9b8dea.tar.bz2 scala-8af1dfade7e0fafcbe7adb4dbea14d734d9b8dea.zip |
fixed ticket #2 (patch from tags/R_2_6_0-RC2), ...
fixed ticket #2 (patch from tags/R_2_6_0-RC2), reorganized test cases
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/ParallelMatching.scala | 31 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/PatternMatchers.scala | 2 | ||||
-rw-r--r-- | test/files/run/bug1093.check | 1 | ||||
-rw-r--r-- | test/files/run/bug1093.scala | 9 | ||||
-rw-r--r-- | test/files/run/bug1094.check | 1 | ||||
-rw-r--r-- | test/files/run/bug1094.scala | 11 | ||||
-rw-r--r-- | test/files/run/bug508.check | 3 | ||||
-rw-r--r-- | test/files/run/bug508.scala | 20 | ||||
-rw-r--r-- | test/files/run/bug789.check | 2 | ||||
-rw-r--r-- | test/files/run/bug789.scala | 31 | ||||
-rw-r--r-- | test/files/run/bug995.check | 1 | ||||
-rw-r--r-- | test/files/run/bug995.scala | 12 | ||||
-rw-r--r-- | test/files/run/patmatnew.scala | 143 |
13 files changed, 126 insertions, 141 deletions
diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index e21ebc42c4..31ec804325 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -814,7 +814,7 @@ trait ParallelMatching { val (casted,srep,frep) = this.getTransition val condUntyped = condition(casted.tpe, this.scrutinee) var cond = rep.handleOuter(typed { condUntyped }) // <- throws exceptions in some situations? - if(needsOuterTest(casted.tpe, this.scrutinee.tpe)) // @todo merge into def condition + if(needsOuterTest(casted.tpe, this.scrutinee.tpe, theOwner)) // @todo merge into def condition cond = addOuterCondition(cond, casted.tpe, mkIdent(this.scrutinee), rep.handleOuter) val succ = repToTree(srep) @@ -1484,35 +1484,16 @@ trait ParallelMatching { gen.mkIsInstanceOf(scrutineeTree, tpe) } - final def needsOuterTest(tpe2test: Type, scrutinee: Type) = tpe2test.normalize match { - case TypeRef(prefix,_,_) => - prefix.termSymbol.isTerm && - !prefix.termSymbol.isPackage && - outerAlwaysEqual(tpe2test, scrutinee) == Some(false) - case _ => - false - } - - /** returns a result if both are TypeRefs, returns Some(true) if left and right are statically known to have - * the same outer, i.e. if their prefixes are the same - */ - final def outerAlwaysEqual(left: Type, right: Type): Option[Boolean] = - (left.normalize, right.normalize) match { - case (TypeRef(lprefix, _, _), TypeRef(rprefix, _, _)) => - //if(!(lprefix =:= rprefix)) { - //DEBUG("DEBUG(outerAlwaysEqual) Some(f) for"+(left,right)) - //} - Some(lprefix =:= rprefix) - case _ => - None - } - /** adds a test comparing the dynamic outer to the static outer */ final def addOuterCondition(cond:Tree, tpe2test: Type, scrutinee: Tree, handleOuter: Tree=>Tree) = { val TypeRef(prefix,_,_) = tpe2test //Console.println("addOuterCondition: "+prefix) assert(prefix ne NoPrefix) - var theRef = gen.mkAttributedRef(prefix.prefix, prefix.termSymbol) + var theRef = prefix match { + case ThisType(clazz) => gen.mkAttributedThis(clazz) + case _ => gen.mkAttributedRef(prefix.prefix, prefix.termSymbol) + } + // needs explicitouter treatment theRef = handleOuter(theRef) diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala index 677c850a92..5d7fc44e9a 100644 --- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala +++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala @@ -1204,7 +1204,7 @@ print() // compare outer instance for patterns like foo1.Bar foo2.Bar if not statically known to match casted.tpe match { - case TypeRef(prefix,_,_) if needsOuterTest(casted.tpe, selector.tpe) => + case TypeRef(prefix,_,_) if needsOuterTest(casted.tpe, selector.tpe, owner) => //@attention, deep typer bug: if we omit "typed" here, we crash when typing the tree that contains this fragment cond = typed{ addOuterCondition(cond, casted.tpe, selector.duplicate, handleOuter) } diff --git a/test/files/run/bug1093.check b/test/files/run/bug1093.check deleted file mode 100644 index 0cfbf08886..0000000000 --- a/test/files/run/bug1093.check +++ /dev/null @@ -1 +0,0 @@ -2 diff --git a/test/files/run/bug1093.scala b/test/files/run/bug1093.scala deleted file mode 100644 index 4cc6181e81..0000000000 --- a/test/files/run/bug1093.scala +++ /dev/null @@ -1,9 +0,0 @@ -// contribution bug #460 - -object Test extends Application { - val x = Some(3) match { - case Some(1 | 2) => 1 - case Some(3) => 2 - } - println(x) -} diff --git a/test/files/run/bug1094.check b/test/files/run/bug1094.check deleted file mode 100644 index bc56c4d894..0000000000 --- a/test/files/run/bug1094.check +++ /dev/null @@ -1 +0,0 @@ -Foo diff --git a/test/files/run/bug1094.scala b/test/files/run/bug1094.scala deleted file mode 100644 index 7fe8072b5f..0000000000 --- a/test/files/run/bug1094.scala +++ /dev/null @@ -1,11 +0,0 @@ -// contribution bug #461 - -object Test extends Application { - def foo(ps: String*) = "Foo" - case class X(p: String, ps: String*) - def bar = - X("a", "b") match { - case X(p, ps @ _*) => foo(ps : _*) - } - println(bar) -} diff --git a/test/files/run/bug508.check b/test/files/run/bug508.check deleted file mode 100644 index 4539bbf2d2..0000000000 --- a/test/files/run/bug508.check +++ /dev/null @@ -1,3 +0,0 @@ -0 -1 -2 diff --git a/test/files/run/bug508.scala b/test/files/run/bug508.scala deleted file mode 100644 index 80485371ea..0000000000 --- a/test/files/run/bug508.scala +++ /dev/null @@ -1,20 +0,0 @@ -object Test { - case class Operator(x: Int); - val EQ = new Operator(2); - - def main(args: Array[String]): Unit = { - val x = Pair(EQ, 0); - analyze(x); // should print "0" - val y = Pair(EQ, 1); - analyze(y); // should print "1" - val z = Pair(EQ, 2); - analyze(z); // should print "2" - } - - def analyze(x: Pair[Operator, Int]) = x match { - case Pair(EQ, 0) => Console.println("0") - case Pair(EQ, 1) => Console.println("1") - case Pair(EQ, 2) => Console.println("2") - case _ => Console.println("undefined on " + x) - } -} diff --git a/test/files/run/bug789.check b/test/files/run/bug789.check deleted file mode 100644 index a98c09dcac..0000000000 --- a/test/files/run/bug789.check +++ /dev/null @@ -1,2 +0,0 @@ -hello size 42 -hello size 42 diff --git a/test/files/run/bug789.scala b/test/files/run/bug789.scala deleted file mode 100644 index 8cd4102dcf..0000000000 --- a/test/files/run/bug789.scala +++ /dev/null @@ -1,31 +0,0 @@ -object Test { // don't do this at home - - trait Impl - - trait SizeImpl extends Impl { def size = 42 } - - trait ColorImpl extends Impl { def color = "red" } - - type Both = SizeImpl with ColorImpl - - def info(x:Impl) = x match { - case x:Both => "size "+x.size+" color "+x.color // you wish - case x:SizeImpl => "size "+x.size - case x:ColorImpl => "color "+x.color - case _ => "n.a." - } - - def info2(x:Impl) = x match { - case x:SizeImpl with ColorImpl => "size "+x.size+" color "+x.color // you wish - case x:SizeImpl => "size "+x.size - case x:ColorImpl => "color "+x.color - case _ => "n.a." - } - - def main(args:Array[String]): Unit = { - // make up some class that has a size - class MyNode extends SizeImpl - Console.println("hello " + info(new MyNode)) - Console.println("hello " + info2(new MyNode)) - } -} diff --git a/test/files/run/bug995.check b/test/files/run/bug995.check deleted file mode 100644 index f0f0e34bb3..0000000000 --- a/test/files/run/bug995.check +++ /dev/null @@ -1 +0,0 @@ -Seq diff --git a/test/files/run/bug995.scala b/test/files/run/bug995.scala deleted file mode 100644 index f7f75b6a02..0000000000 --- a/test/files/run/bug995.scala +++ /dev/null @@ -1,12 +0,0 @@ -object Test extends Application { - def foo(v: Any): String = v match { - case s: Seq[_] => - "Seq" - // see Burak's hack in object Seq.unapplySeq - //case a: AnyRef if runtime.ScalaRunTime.isArray(a) => - // "Array" - case _ => - v.toString - } - Console.println(foo(Array(0))) -} diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala index fdb01c9aec..09b12f710c 100644 --- a/test/files/run/patmatnew.scala +++ b/test/files/run/patmatnew.scala @@ -33,11 +33,16 @@ object Test extends TestConsoleMain { TestEqualsPatternOpt, new TestStream, new Test903, - new Test1093, new Test1163_Order, new TestUnbox, + Bug457, + Bug508, + Bug789, + Bug995, + Bug1093, + Bug1094, ClassDefInGuard, - Bug457 + Ticket_2 ) class Foo(j:Int) { @@ -225,16 +230,6 @@ object Test extends TestConsoleMain { Some(p.father) } - class Test1093 extends TestCase("bug1093") { - override def runTest { - val x = Some(3) match { - case Some(1 | 2) => 1 - case Some(3) => 2 - } - assertEquals("ok", 2, x) - } - } - class Test903 extends TestCase("bug903") { override def runTest = { @@ -451,24 +446,18 @@ object Test extends TestConsoleMain { } } - + // bug#457 object Bug457 extends TestCase("Bug457") { - def method1() = { - val x = "Hello, world"; - val y = 100; - + val x = "Hello, world"; val y = 100; y match { case _: Int if (x match { case t => t.trim().length() > 0 }) => false; case _ => true; - } - } + }} def method2(): scala.Boolean = { - val x: String = "Hello, world"; - val y: scala.Int = 100; - { + val x: String = "Hello, world"; val y: scala.Int = 100; { var temp1: scala.Int = y; var result: scala.Boolean = false; if ( @@ -483,16 +472,122 @@ object Test extends TestConsoleMain { result else throw new MatchError("crazybox.scala, line 9") - } - } + }} override def runTest { method1(); method2(); } + } + + // bug#508 + + object Bug508 extends TestCase("aladdin #508") { + case class Operator(x: Int); + val EQ = new Operator(2); + + def analyze(x: Pair[Operator, Int]) = x match { + case Pair(EQ, 0) => "0" + case Pair(EQ, 1) => "1" + case Pair(EQ, 2) => "2" + } + override def runTest { + val x = Pair(EQ, 0); + assertEquals("0", analyze(x)); // should print "0" + val y = Pair(EQ, 1); + assertEquals("1", analyze(y)); // should print "1" + val z = Pair(EQ, 2); + assertEquals("2", analyze(z)); // should print "2" + } + } + + // bug#789 + + object Bug789 extends TestCase("aladdin #789") { // don't do this at home + + trait Impl + + trait SizeImpl extends Impl { def size = 42 } + + trait ColorImpl extends Impl { def color = "red" } + + type Both = SizeImpl with ColorImpl + + def info(x:Impl) = x match { + case x:Both => "size "+x.size+" color "+x.color // you wish + case x:SizeImpl => "!size "+x.size + case x:ColorImpl => "color "+x.color + case _ => "n.a." + } + def info2(x:Impl) = x match { + case x:SizeImpl with ColorImpl => "size "+x.size+" color "+x.color // you wish + case x:SizeImpl => "!size "+x.size + case x:ColorImpl => "color "+x.color + case _ => "n.a." + } + + override def runTest { + // make up some class that has a size + class MyNode extends SizeImpl + assertEquals("!size 42", info(new MyNode)) + assertEquals("!size 42", info2(new MyNode)) + } } + // bug#995 + + object Bug995 extends TestCase("aladdin #995") { + def foo(v: Any): String = v match { + case s: Seq[_] => "Seq" // see hack in object Seq.unapplySeq + //case a: AnyRef if runtime.ScalaRunTime.isArray(a) => "Array" + case _ => v.toString + } + override def runTest { assertEquals("Seq", foo(Array(0))) } + } + + // bug#1093 (contribution #460) + + object Bug1093 extends TestCase("aladdin #1093") { + override def runTest {assertTrue(Some(3) match { + case Some(1 | 2) => false + case Some(3) => true + })} + } + + // bug#1094 (contribution #461) + + object Bug1094 extends TestCase("aladdin #1094") { + def foo(ps: String*) = "Foo" + case class X(p: String, ps: String*) + def bar = + X("a", "b") match { + case X(p, ps @ _*) => foo(ps : _*) + } + override def runTest { assertEquals("Foo", bar) } + } + + // #2 + + class Outer_2 { + case class Foo(x: int, y: int) { + override def equals(other: Any) = other match { + case Outer_2.this.Foo(`x`, `y`) => true + case _ => false + } + } + } + + object Ticket_2 extends TestCase("#2") { override def runTest { + val o1 = new Outer_2; val o2 = new Outer_2; val x: Any = o1.Foo(1, 2); val y: Any = o2.Foo(1, 2) + assertFalse("equals test returns true (but should not)", x equals y) + assertTrue("match enters wrong case", x match { + case o2.Foo(x, y) => false; + case o1.Foo(x, y) => true + case _ => false + }) + }} } + |