Skip to content

Commit ab93bc8

Browse files
committed
Fix #1665: Check that != has an operand on the left.
1 parent 5cef7a9 commit ab93bc8

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/dotty/tools/dotc/transform/InterceptedMethods.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,22 @@ class InterceptedMethods extends MiniPhaseTransform {
9696
s"that means the intercepted methods set doesn't match the code")
9797
tree
9898
}
99-
lazy val Select(qual, _) = tree.fun
99+
lazy val qual = tree.fun match {
100+
case Select(qual, _) => qual
101+
case Ident(name) => EmptyTree
102+
}
100103
val Any_## = this.Any_##
101104
val Any_!= = defn.Any_!=
102105
val rewrite: Tree = tree.fun.symbol match {
103106
case Any_## =>
104107
poundPoundValue(qual)
105108
case Any_!= =>
109+
if (qual.isEmpty) {
110+
ctx.error(ex"Binary operation != should have an operand on the left hand side", tree.fun.pos)
111+
tree
112+
} else {
106113
qual.select(defn.Any_==).appliedToArgs(tree.args).select(defn.Boolean_!)
114+
}
107115
/*
108116
/* else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) {
109117
// todo: this is needed to support value classes

tests/neg/i1665-nonfuzzy.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
object Test {
3+
!=(1) // error: Binary operation != should have an operand on the left hand side
4+
!=("abc") // error: Binary operation != should have an operand on the left hand side
5+
}

tests/neg/i1665.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import scala.reflect.runtime.universe._
3+
import scala.reflect.runtime.{currentMirror => cm}
4+
5+
object Test extends App {
6+
val mutant = new { val x = 2 }
7+
val c = cm.classSymbol(mutant.getClass)
8+
!=(c) // error: Binary operation != should have an operand on the left hand side
9+
println(c.fullName)
10+
c.info.toString.lines
11+
.filter(_ != " private var bitmap$init$0: Boolean") foreach println
12+
}

0 commit comments

Comments
 (0)