From 26bca73b09d29a7978acdda36d2f85478343f9f4 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 5 Jul 2009 23:22:43 +0000 Subject: Implemented proposed strategy for #1503 and mov... Implemented proposed strategy for #1503 and moved test case out of pending (and fixed it so it didn't throw a match error.) --- src/compiler/scala/tools/nsc/matching/ParallelMatching.scala | 5 ++++- test/files/run/castsingleton.check | 2 ++ test/files/run/castsingleton.scala | 11 +++++++++++ test/files/run/patmatnew.scala | 7 +++++-- test/pending/run/castsingleton.check | 2 -- test/pending/run/castsingleton.scala | 10 ---------- 6 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 test/files/run/castsingleton.check create mode 100644 test/files/run/castsingleton.scala delete mode 100644 test/pending/run/castsingleton.check delete mode 100644 test/pending/run/castsingleton.scala diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index 7f7b492b79..1905cc31b5 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -1180,7 +1180,10 @@ trait ParallelMatching extends ast.TreeDSL { case v @ Constant(null) if isAnyRef(scrutTree.tpe) => scrutTree ANY_EQ NULL case v => scrutTree ANY_== Literal(v) } - case _: SingletonType if useEqTest => REF(tpe.termSymbol) ANY_== scrutTree + case _: SingletonType if useEqTest => + // See ticket #1503 for why both these checks are necessary. + (REF(tpe.termSymbol) ANY_== scrutTree) AND (scrutTree IS tpe.widen) + case _ if scrutTree.tpe <:< tpe && isAnyRef(tpe) => scrutTree OBJ_!= NULL case _ => scrutTree IS tpe }) diff --git a/test/files/run/castsingleton.check b/test/files/run/castsingleton.check new file mode 100644 index 0000000000..49742281f0 --- /dev/null +++ b/test/files/run/castsingleton.check @@ -0,0 +1,2 @@ +L() +L() diff --git a/test/files/run/castsingleton.scala b/test/files/run/castsingleton.scala new file mode 100644 index 0000000000..f907467741 --- /dev/null +++ b/test/files/run/castsingleton.scala @@ -0,0 +1,11 @@ +object Test extends Application { + case class L(); + object N extends L(); + + def empty(xs : L) : Unit = xs match { + case x@N => println(x); println(x); + case x => println(x); println(x); + } + + empty(L()) +} diff --git a/test/files/run/patmatnew.scala b/test/files/run/patmatnew.scala index a16f300414..0ab5e92099 100644 --- a/test/files/run/patmatnew.scala +++ b/test/files/run/patmatnew.scala @@ -876,8 +876,11 @@ object C { } override def runTest() { - assertTrue(empty( new L(Nil) )) - assertTrue(singleton( new L(List(1)) )) + // We no longer assert these are true, because they are no longer true! + // See ticket #1503 for details, but it is unsound to let L(Nil) be + // seen as an N by the LHS of a match. + // assertTrue(empty( new L(Nil) )) + // assertTrue(singleton( new L(List(1)) )) } } // end Ticket346 diff --git a/test/pending/run/castsingleton.check b/test/pending/run/castsingleton.check deleted file mode 100644 index 49742281f0..0000000000 --- a/test/pending/run/castsingleton.check +++ /dev/null @@ -1,2 +0,0 @@ -L() -L() diff --git a/test/pending/run/castsingleton.scala b/test/pending/run/castsingleton.scala deleted file mode 100644 index 171b380dc9..0000000000 --- a/test/pending/run/castsingleton.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Test extends Application { - case class L(); - object N extends L(); - - def empty(xs : L) : Unit = xs match { - case x@N => println(x); println(x); - } - - empty(L()) -} -- cgit v1.2.3