summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2013-01-03 20:35:22 -0800
committerPaul Phillips <paulp@improving.org>2013-01-03 23:38:51 -0800
commiteeb6ee6eb21e7bd473ab5775474444b5d1b72856 (patch)
treeec58c47937d7544d6f0b2563bcaaee04c605da74 /src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
parente112ac94d04be7ee715ebf8724709123b0f3e1f6 (diff)
downloadscala-eeb6ee6eb21e7bd473ab5775474444b5d1b72856.tar.gz
scala-eeb6ee6eb21e7bd473ab5775474444b5d1b72856.tar.bz2
scala-eeb6ee6eb21e7bd473ab5775474444b5d1b72856.zip
SI-6911, regression in generated case class equality.
Caught out by the different semantics of isInstanceOf and pattern matching. trait K { case class CC(name: String) } object Foo extends K object Bar extends K Foo.CC("a") == Bar.CC("a") That expression is supposed to be false, and with this commit it is once again.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
index 17e67e6429..a907ab6c66 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
@@ -157,11 +157,23 @@ trait SyntheticMethods extends ast.TreeDSL {
Ident(m.firstParam) IS_OBJ classExistentialType(clazz))
}
- /** (that.isInstanceOf[this.C])
- * where that is the given methods first parameter.
+ /** that match { case _: this.C => true ; case _ => false }
+ * where `that` is the given method's first parameter.
+ *
+ * An isInstanceOf test is insufficient because it has weaker
+ * requirements than a pattern match. Given an inner class Foo and
+ * two different instantiations of the container, an x.Foo and and a y.Foo
+ * are both .isInstanceOf[Foo], but the one does not match as the other.
*/
- def thatTest(eqmeth: Symbol): Tree =
- gen.mkIsInstanceOf(Ident(eqmeth.firstParam), classExistentialType(clazz), true, false)
+ def thatTest(eqmeth: Symbol): Tree = {
+ Match(
+ Ident(eqmeth.firstParam),
+ List(
+ CaseDef(Typed(Ident(nme.WILDCARD), TypeTree(clazz.tpe)), EmptyTree, TRUE),
+ CaseDef(WILD.empty, EmptyTree, FALSE)
+ )
+ )
+ }
/** (that.asInstanceOf[this.C])
* where that is the given methods first parameter.