summaryrefslogtreecommitdiff
path: root/test/files/run/richWrapperEquals.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-11-01 16:27:13 +0000
committerPaul Phillips <paulp@improving.org>2010-11-01 16:27:13 +0000
commit9b54520a8c5a4f130a1fabbb0d0e7a3ec9022f41 (patch)
tree254c5a777abd099826873ac5ee686a5452370fdd /test/files/run/richWrapperEquals.scala
parent1df37f476926ada63e223abcbe119147b6d693b3 (diff)
downloadscala-9b54520a8c5a4f130a1fabbb0d0e7a3ec9022f41.tar.gz
scala-9b54520a8c5a4f130a1fabbb0d0e7a3ec9022f41.tar.bz2
scala-9b54520a8c5a4f130a1fabbb0d0e7a3ec9022f41.zip
Eliminated duplication among the Rich* wrappers...
Eliminated duplication among the Rich* wrappers, careful not to impact performance on RichInt in particular. Attempted to make Proxy a little bit typier. Proxy creates an asymmetric equals method by design so it's unfixable in that regard, but achieved a minor miracle anyway by making the Rich* wrappers behave symmetrically. Note: said miracle involved having the wrappers extend ScalaNumber in order to induce the special == semantics. This in turn led to implicit conversion conflicts with the boxed types on methods like .intValue(). Resolved by moving the Rich* implicits into LowPriorityImplicits. This of course also removed the intentional ambiguity which prevents primitives from automatically becoming AnyRefs. Solved THAT one by creating dedicated, laser-precise ambiguity creating implicits in Predef which exclude only the AnyRef methods. Although this is admittedly less than elegant, it is still better than it was: this way it is direct and explicit rather than depending upon the "implicit implicit conflict" where the barrier to promotion is intermingled with the definitions of wrapper classes. (See the history of BoxedUnit/RichUnit for a good example of why these concerns require separation.) It's all worth it: assert(intWrapper(5) == 5) assert(5 == intWrapper(5)) assert(5 == (5: java.lang.Integer)) assert((5: java.lang.Integer) == 5) assert((5: java.lang.Integer) == intWrapper(5)) assert(intWrapper(5) == (5: java.lang.Integer)) Review by community.
Diffstat (limited to 'test/files/run/richWrapperEquals.scala')
-rw-r--r--test/files/run/richWrapperEquals.scala10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/files/run/richWrapperEquals.scala b/test/files/run/richWrapperEquals.scala
new file mode 100644
index 0000000000..44beb133b3
--- /dev/null
+++ b/test/files/run/richWrapperEquals.scala
@@ -0,0 +1,10 @@
+object Test {
+ def main(args: Array[String]): Unit = {
+ assert(intWrapper(5) == 5)
+ assert(5 == intWrapper(5))
+ assert(5 == (5: java.lang.Integer))
+ assert((5: java.lang.Integer) == 5)
+ assert((5: java.lang.Integer) == intWrapper(5))
+ assert(intWrapper(5) == (5: java.lang.Integer))
+ }
+}