diff options
author | Martin Odersky <odersky@gmail.com> | 2007-03-22 18:22:49 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2007-03-22 18:22:49 +0000 |
commit | 800ce668acb253c3d5e57b5230d913ad155a0f74 (patch) | |
tree | a7526664522ee11348087e5bb80957182b9ba17e /src | |
parent | 0196b0e057dcd62903b6635f53d2857ea182280a (diff) | |
download | scala-800ce668acb253c3d5e57b5230d913ad155a0f74.tar.gz scala-800ce668acb253c3d5e57b5230d913ad155a0f74.tar.bz2 scala-800ce668acb253c3d5e57b5230d913ad155a0f74.zip |
modified sinsibility checks and test cases
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Definitions.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 21 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 3f46850e30..54aa364ddd 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -362,6 +362,7 @@ trait Definitions requires SymbolTable { // boxed classes var BoxedArrayClass: Symbol = _ + var BoxedNumberClass: Symbol = _ var BoxedAnyArrayClass: Symbol = _ var BoxedObjectArrayClass: Symbol = _ var BoxedUnitClass: Symbol = _ @@ -862,6 +863,7 @@ trait Definitions requires SymbolTable { PatternWildcard = NoSymbol.newValue(NoPos, "_").setInfo(AllClass.typeConstructor) + BoxedNumberClass = getClass("scala.runtime.BoxedNumber") BoxedArrayClass = getClass("scala.runtime.BoxedArray") BoxedAnyArrayClass = getClass("scala.runtime.BoxedAnyArray") BoxedObjectArrayClass = getClass("scala.runtime.BoxedObjectArray") diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index a5f6f785b9..78ccc5f7f4 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -454,23 +454,24 @@ abstract class RefChecks extends InfoTransform { def nonSensibleWarning(what: String, alwaysEqual: boolean) = unit.warning(pos, "comparing "+what+" using `"+name.decode+"' will always yield "+ (alwaysEqual == (name == nme.EQ || name == nme.LE || name == nme.GE))) - def nonSensible(alwaysEqual: boolean) = - nonSensibleWarning("values of types "+qual.tpe.widen+" and "+args.head.tpe.widen, + def nonSensible(pre: String, alwaysEqual: boolean) = + nonSensibleWarning(pre+"values of types "+qual.tpe.widen+" and "+args.head.tpe.widen, alwaysEqual) + def hasObjectEquals = receiver.info.member(nme.equals_) == Object_equals if (formal == UnitClass && actual == UnitClass) - nonSensible(true) + nonSensible("", true) else if ((receiver == BooleanClass || receiver == UnitClass) && !(receiver isSubClass actual)) - nonSensible(false) + nonSensible("", false) else if (isNumericValueClass(receiver) && !isNumericValueClass(actual) && + !(actual isSubClass BoxedNumberClass) && !(receiver isSubClass actual)) - nonSensible(false) - else if ((receiver hasFlag FINAL) && - (fn.symbol == Object_== || fn.symbol == Object_!=) && - !(receiver isSubClass actual)) - nonSensible(false) - else if (isNew && (fn.symbol == Object_== || fn.symbol == Object_!=)) + nonSensible("", false) + else if ((receiver hasFlag FINAL) && hasObjectEquals && !isValueClass(receiver) && + !(receiver isSubClass actual) && actual != AllRefClass) + nonSensible("non-null ", false) + else if (isNew && hasObjectEquals) nonSensibleWarning("a fresh object", false) case _ => } |