From cbf8534ff7a04603e7c47c0a2422c012ddd44810 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 10 Sep 2011 00:35:05 +0000 Subject: Helping Proxy equal itself. Fix for bumpy proxy equals. Closes SI-4807, no review. --- src/compiler/scala/reflect/internal/Symbols.scala | 2 +- src/library/scala/Proxy.scala | 7 +++---- test/files/run/proxy.check | 2 ++ test/files/run/proxy.scala | 8 ++++++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index 60b0c411da..60d544fe17 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -2134,7 +2134,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => * * If typeParams is nonEmpty, calling tpe may hide errors or * introduce spurious ones. (For example, when deriving a type from - * the symbol of a type argument that must be higher-kinded.) As far + * the symbol of a type argument that may be higher-kinded.) As far * as I can tell, it only makes sense to call tpe in conjunction * with a substitution that replaces the generated dummy type * arguments by their actual types. diff --git a/src/library/scala/Proxy.scala b/src/library/scala/Proxy.scala index f79b01bf83..383ff5b3bb 100644 --- a/src/library/scala/Proxy.scala +++ b/src/library/scala/Proxy.scala @@ -27,11 +27,10 @@ trait Proxy { override def hashCode: Int = self.hashCode override def equals(that: Any): Boolean = that match { - case null => false - case x: Equals => (x canEqual self) && (x equals self) - case x => (x equals self) + case null => false + case x: AnyRef => (x eq this) || (x eq self.asInstanceOf[AnyRef]) || (x equals self) } - override def toString: String = self.toString + override def toString = "" + self } object Proxy { diff --git a/test/files/run/proxy.check b/test/files/run/proxy.check index 9eb68b1e90..c40b3db7c2 100644 --- a/test/files/run/proxy.check +++ b/test/files/run/proxy.check @@ -2,3 +2,5 @@ false true false false +true +true diff --git a/test/files/run/proxy.scala b/test/files/run/proxy.scala index 6f9e83c7f1..8a6385dc85 100644 --- a/test/files/run/proxy.scala +++ b/test/files/run/proxy.scala @@ -6,4 +6,12 @@ object Test extends App { println(p equals 2) println(p equals 3) println(p equals null) + + case class Bippy(a: String) extends Proxy { + def self = a + } + + val label = Bippy("bippy!") + println(label == label) + println(label == "bippy!") } -- cgit v1.2.3