Skip to content

Commit b0a64ec

Browse files
authored
Merge pull request #1685 from dotty-staging/fix-1665
Fix #1665: Check that != has an operand on the left.
2 parents 47d2084 + 929efec commit b0a64ec

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,24 @@ 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 @ Ident(_) =>
102+
ident.tpe match {
103+
case TermRef(prefix: TermRef, _) =>
104+
tpd.ref(prefix)
105+
case TermRef(prefix: ThisType, _) =>
106+
tpd.This(prefix.cls)
107+
}
108+
109+
}
100110
val Any_## = this.Any_##
101111
val Any_!= = defn.Any_!=
102112
val rewrite: Tree = tree.fun.symbol match {
103113
case Any_## =>
104-
poundPoundValue(qual)
114+
poundPoundValue(qual)
105115
case Any_!= =>
106-
qual.select(defn.Any_==).appliedToArgs(tree.args).select(defn.Boolean_!)
116+
qual.select(defn.Any_==).appliedToArgs(tree.args).select(defn.Boolean_!)
107117
/*
108118
/* else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) {
109119
// todo: this is needed to support value classes
@@ -121,7 +131,7 @@ class InterceptedMethods extends MiniPhaseTransform {
121131
// we get a primitive form of _getClass trying to target a boxed value
122132
// so we need replace that method name with Object_getClass to get correct behavior.
123133
// See SI-5568.
124-
qual.selectWithSig(defn.Any_getClass).appliedToNone
134+
qual.selectWithSig(defn.Any_getClass).appliedToNone
125135
case _ =>
126136
tree
127137
}

tests/pos/i1665.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
object Test {
3+
!=(1)
4+
!=("abc")
5+
1 != this
6+
!=(this)
7+
}

0 commit comments

Comments
 (0)