diff options
author | Som Snytt <som.snytt@gmail.com> | 2012-05-21 21:25:50 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2012-05-21 21:25:50 -0700 |
commit | e3b924e3e287baab36693afb92fb9988c56a57a1 (patch) | |
tree | befa8c366c252671d8ee2c19d3490e8ff82a7dbf /src/compiler | |
parent | f406550146250f5a6036d3d778582efa6d68252a (diff) | |
download | scala-e3b924e3e287baab36693afb92fb9988c56a57a1.tar.gz scala-e3b924e3e287baab36693afb92fb9988c56a57a1.tar.bz2 scala-e3b924e3e287baab36693afb92fb9988c56a57a1.zip |
SI-5779: Wrong warning message (comparing values of types Float/Double and Number using `==' will always yield false)
BoxesRuntime knows how to compare java.lang.Number, so we must not warn.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/reflect/internal/Definitions.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 12 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 0612dcdfd4..00afdd37a6 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -404,6 +404,7 @@ trait Definitions extends reflect.api.StandardDefinitions { lazy val JavaSerializableClass = requiredClass[java.io.Serializable] modifyInfo fixupAsAnyTrait lazy val ComparableClass = requiredClass[java.lang.Comparable[_]] modifyInfo fixupAsAnyTrait lazy val JavaCloneableClass = requiredClass[java.lang.Cloneable] + lazy val JavaNumberClass = requiredClass[java.lang.Number] lazy val RemoteInterfaceClass = requiredClass[java.rmi.Remote] lazy val RemoteExceptionClass = requiredClass[java.rmi.RemoteException] diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 4e578e3f0d..2935305c2a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1085,13 +1085,16 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R def isBoolean(s: Symbol) = unboxedValueClass(s) == BooleanClass def isUnit(s: Symbol) = unboxedValueClass(s) == UnitClass def isNumeric(s: Symbol) = isNumericValueClass(unboxedValueClass(s)) || (s isSubClass ScalaNumberClass) + def isJavaNumeric(s: Symbol) = s isSubClass JavaNumberClass def isSpecial(s: Symbol) = isPrimitiveValueClass(unboxedValueClass(s)) || (s isSubClass ScalaNumberClass) || isMaybeValue(s) def possibleNumericCount = onSyms(_ filter (x => isNumeric(x) || isMaybeValue(x)) size) val nullCount = onSyms(_ filter (_ == NullClass) size) + var sensicality = false def nonSensibleWarning(what: String, alwaysEqual: Boolean) = { val msg = alwaysEqual == (name == nme.EQ || name == nme.eq) unit.warning(pos, "comparing "+what+" using `"+name.decode+"' will always yield " + msg) + sensicality = true } def nonSensible(pre: String, alwaysEqual: Boolean) = nonSensibleWarning(pre+"values of types "+typesString, alwaysEqual) @@ -1123,10 +1126,11 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R else if (!isUnit(actual) && !isMaybeValue(actual)) // () == "abc" nonSensiblyNeq() } - else if (isNumeric(receiver)) { - if (!isNumeric(actual) && !forMSIL) + else if (isNumeric(receiver) || (!forMSIL && isJavaNumeric(receiver))) { + if (!isNumeric(actual) && !forMSIL && !isJavaNumeric(actual)) if (isUnit(actual) || isBoolean(actual) || !isMaybeValue(actual)) // 5 == "abc" nonSensiblyNeq() + sensicality = true } else if (isWarnable && !isCaseEquals) { if (isNew(qual)) // new X == y @@ -1142,7 +1146,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R } // possibleNumericCount is insufficient or this will warn on e.g. Boolean == j.l.Boolean - if (isWarnable && nullCount == 0 && !(isSpecial(receiver) && isSpecial(actual))) { + if (!sensicality && isWarnable && nullCount == 0 && !(isSpecial(receiver) && isSpecial(actual))) { // better to have lubbed and lost def warnIfLubless(): Unit = { val common = global.lub(List(actual.tpe, receiver.tpe)) @@ -1155,7 +1159,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R if (isCaseEquals) { def thisCase = receiver.info.member(nme.equals_).owner actual.info.baseClasses.find(_.isCase) match { - case Some(p) if (p != thisCase) => nonSensible("case class ", false) + case Some(p) if p != thisCase => nonSensible("case class ", false) case None => // stronger message on (Some(1) == None) //if (receiver.isCase && receiver.isEffectivelyFinal && !(receiver isSubClass actual)) nonSensiblyNeq() |