Skip to content

Commit

Permalink
SI-6091 overeager warning for reference equality
Browse files Browse the repository at this point in the history
Don't warn on eq and ne unless they're the real eq or ne.
  • Loading branch information
paulp committed May 2, 2013
1 parent 98972c9 commit 62cdd7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Expand Up @@ -1063,9 +1063,13 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
case _ =>
}

private def isObjectOrAnyComparisonMethod(sym: Symbol) = sym match {
case Object_eq | Object_ne | Object_== | Object_!= | Any_== | Any_!= => true
case _ => false
}
def checkSensible(pos: Position, fn: Tree, args: List[Tree]) = fn match {
case Select(qual, name @ (nme.EQ | nme.NE | nme.eq | nme.ne)) if args.length == 1 =>
def isReferenceOp = name == nme.eq || name == nme.ne
case Select(qual, name @ (nme.EQ | nme.NE | nme.eq | nme.ne)) if args.length == 1 && isObjectOrAnyComparisonMethod(fn.symbol) =>
def isReferenceOp = fn.symbol == Object_eq || fn.symbol == Object_ne
def isNew(tree: Tree) = tree match {
case Function(_, _)
| Apply(Select(New(_), nme.CONSTRUCTOR), _) => true
Expand Down
1 change: 1 addition & 0 deletions test/files/pos/t6091.flags
@@ -0,0 +1 @@
-Xfatal-warnings -Xlint
10 changes: 10 additions & 0 deletions test/files/pos/t6091.scala
@@ -0,0 +1,10 @@
object Foo { def eq(x:Int) = x }

class X { def ==(other: String) = true }

object Test {
def main(args: Array[String]): Unit = {
Foo eq 1
new X == null
}
}

0 comments on commit 62cdd7f

Please sign in to comment.