diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 15 | ||||
-rw-r--r-- | src/library/scala/runtime/Comparator.java | 4 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index b668e28c05..5ddf6b052d 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -1378,15 +1378,22 @@ abstract class GenICode extends SubComponent { local } + /** True if the equality comparison is between values that require the use of the rich equality + * comparator (scala.runtime.Comparator.equals). This is the case when either side of the + * comparison might have a run-time type subtype of java.lang.Number or java.lang.Character. + * When it is statically known that both sides are equal and subtypes of Number of Character, + * not using the rich equality is possible (their own equals method will do ok.)*/ def mustUseAnyComparator: Boolean = { val lsym = l.tpe.symbol val rsym = r.tpe.symbol (lsym == definitions.ObjectClass) || (rsym == definitions.ObjectClass) || - (lsym isNonBottomSubClass definitions.BoxedNumberClass)|| - (!forMSIL && (lsym isNonBottomSubClass BoxedCharacterClass)) || - (rsym isNonBottomSubClass definitions.BoxedNumberClass) || - (!forMSIL && (rsym isNonBottomSubClass BoxedCharacterClass)) + (lsym != rsym) && ( + (lsym isNonBottomSubClass definitions.BoxedNumberClass) || + (!forMSIL && (lsym isNonBottomSubClass BoxedCharacterClass)) || + (rsym isNonBottomSubClass definitions.BoxedNumberClass) || + (!forMSIL && (rsym isNonBottomSubClass BoxedCharacterClass)) + ) } if (mustUseAnyComparator) { diff --git a/src/library/scala/runtime/Comparator.java b/src/library/scala/runtime/Comparator.java index c73c7506ba..705bf30d5c 100644 --- a/src/library/scala/runtime/Comparator.java +++ b/src/library/scala/runtime/Comparator.java @@ -36,8 +36,8 @@ public class Comparator { * ICode phase, method <code>genEqEqPrimitive</code>) only when either * side of the comparison is a subclass of <code>AnyVal</code>, of * <code>java.lang.Number</code>, of <code>java.lang.Character</code> or - * is exactly <code>Any</code> or <code>AnyRef</code>. - */ + * is exactly <code>Any</code> or <code>AnyRef</code>, but when both sides + * have different types. */ public static boolean equals(Object a, Object b) { if (a == null) return b == null; |