diff options
author | Paul Phillips <paulp@improving.org> | 2011-09-09 00:14:43 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-09-09 00:14:43 +0000 |
commit | ca15d245fd8624392756df5e79f893bea8ce53ef (patch) | |
tree | 044b7774a11c755700a8a2a8c33babce1083c6bb /src | |
parent | 65a785e17793e39a67a26ad30abe0a02edc5bf89 (diff) | |
download | scala-ca15d245fd8624392756df5e79f893bea8ce53ef.tar.gz scala-ca15d245fd8624392756df5e79f893bea8ce53ef.tar.bz2 scala-ca15d245fd8624392756df5e79f893bea8ce53ef.zip |
Brought back unrelated type comparison warning.
Figured out how to turn it on by default, even.
Closes SI-4979, no review.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 0ff886dea6..1b28027bb1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -966,10 +966,9 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R case _ => false } def underlyingClass(tp: Type): Symbol = { - var sym = tp.widen.typeSymbol - while (sym.isAbstractType) - sym = sym.info.bounds.hi.widen.typeSymbol - sym + val sym = tp.widen.typeSymbol + if (sym.isAbstractType) underlyingClass(sym.info.bounds.hi) + else sym } val actual = underlyingClass(args.head.tpe) val receiver = underlyingClass(qual.tpe) @@ -1009,8 +1008,11 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R def nonSensible(pre: String, alwaysEqual: Boolean) = nonSensibleWarning(pre+"values of types "+typesString, alwaysEqual) - def unrelatedTypes() = - unit.warning(pos, typesString + " are unrelated: should not compare equal") + def unrelatedTypes() = { + val msg = if (name == nme.EQ || name == nme.eq) + "never compare equal" else "always compare unequal" + unit.warning(pos, typesString + " are unrelated: they will most likely " + msg) + } if (nullCount == 2) nonSensible("", true) // null == null @@ -1047,13 +1049,14 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R nonSensible("", false) } } - // Warning on types without a parental relationship. Uncovers a lot of - // bugs, but not always right to warn. - if (false) { - if (nullCount == 0 && possibleNumericCount < 2 && !(receiver isSubClass actual) && !(actual isSubClass receiver)) + + if (nullCount == 0 && possibleNumericCount < 2) { + if (actual isSubClass receiver) () + else if (receiver isSubClass actual) () + // warn only if they have no common supertype below Object + else if (ObjectClass.tpe <:< global.lub(List(actual.tpe, receiver.tpe))) unrelatedTypes() } - case _ => } |