diff options
author | Paul Phillips <paulp@improving.org> | 2011-10-18 17:57:29 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-10-18 17:57:29 +0000 |
commit | d0a36c66cb18d94d15d44e5a04ed91ab00a43418 (patch) | |
tree | c0f1dc70b271d09f776399c0b3e70235500d0a52 /src/compiler | |
parent | 23ab7e3c9a46ef6c509a452f8ee3d2f224235bde (diff) | |
download | scala-d0a36c66cb18d94d15d44e5a04ed91ab00a43418.tar.gz scala-d0a36c66cb18d94d15d44e5a04ed91ab00a43418.tar.bz2 scala-d0a36c66cb18d94d15d44e5a04ed91ab00a43418.zip |
Fix for comparison warnings.
true == new java.lang.Boolean(true) will in fact sometimes be true. Also
fixes a bug caused by this change in r23627.
- lazy val SerializableClass = getClass(sn.Serializable)
+ lazy val SerializableClass = getClass("scala.Serializable")
It used to be java.io.Serializable. Hey, let's not change the meaning of
existing symbols which are in active use. No review.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/reflect/internal/Definitions.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala index 654639adae..4ee717ce75 100644 --- a/src/compiler/scala/reflect/internal/Definitions.scala +++ b/src/compiler/scala/reflect/internal/Definitions.scala @@ -784,12 +784,12 @@ trait Definitions extends reflect.api.StandardDefinitions { /** Is symbol a boxed value class, e.g. java.lang.Integer? */ def isBoxedValueClass(sym: Symbol) = boxedValueClassesSet(sym) - /** If symbol is a value class, return the value class, with the exception - * that BoxedUnit remains BoxedUnit. If not a value class, NoSymbol. + /** If symbol is a value class (boxed or not), return the unboxed + * value class. Otherwise, NoSymbol. */ def unboxedValueClass(sym: Symbol): Symbol = if (isValueClass(sym)) sym - else if (sym == BoxedUnitClass) sym + else if (sym == BoxedUnitClass) UnitClass else boxedClass.map(_.swap).getOrElse(sym, NoSymbol) /** Is type's symbol a numeric value class? */ diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index c9237627e7..a5053eb559 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1017,7 +1017,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R def typesString = normalizeAll(qual.tpe.widen)+" and "+normalizeAll(args.head.tpe.widen) /** Symbols which limit the warnings we can issue since they may be value types */ - val isMaybeValue = Set(AnyClass, AnyRefClass, AnyValClass, ObjectClass, ComparableClass, SerializableClass) + val isMaybeValue = Set(AnyClass, AnyRefClass, AnyValClass, ObjectClass, ComparableClass, JavaSerializableClass) // Whether def equals(other: Any) is overridden def isUsingDefaultEquals = { @@ -1035,6 +1035,7 @@ 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 isSpecial(s: Symbol) = isValueClass(unboxedValueClass(s)) || (s isSubClass ScalaNumberClass) || isMaybeValue(s) def possibleNumericCount = onSyms(_ filter (x => isNumeric(x) || isMaybeValue(x)) size) val nullCount = onSyms(_ filter (_ == NullClass) size) @@ -1088,7 +1089,8 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R } } - if (nullCount == 0 && possibleNumericCount < 2) { + // possibleNumericCount is insufficient or this will warn on e.g. Boolean == j.l.Boolean + if (nullCount == 0 && !(isSpecial(receiver) && isSpecial(actual))) { if (actual isSubClass receiver) () else if (receiver isSubClass actual) () // warn only if they have no common supertype below Object |