File tree 3 files changed +38
-2
lines changed
src/dotty/tools/dotc/transform 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -96,14 +96,31 @@ class InterceptedMethods extends MiniPhaseTransform {
96
96
s " that means the intercepted methods set doesn't match the code " )
97
97
tree
98
98
}
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 , name) =>
104
+ tpd.ref(prefix)
105
+ case TermRef (prefix : ThisType , name) =>
106
+ tpd.This (prefix.cls)
107
+ }
108
+
109
+ }
100
110
val Any_## = this .Any_##
101
111
val Any_!= = defn.Any_!=
102
112
val rewrite : Tree = tree.fun.symbol match {
103
113
case Any_## =>
104
114
poundPoundValue(qual)
105
115
case Any_!= =>
106
- qual.select(defn.Any_== ).appliedToArgs(tree.args).select(defn.Boolean_! )
116
+ assert(tree.args.size == 1 )
117
+ val lhs = qual.tpe
118
+ val rhs = tree.args.head.tpe
119
+ if (! (lhs <:< rhs || rhs <:< lhs) && rhs != defn.NullType && lhs != defn.NullType ) {
120
+ ctx.warning(ex " comparing values of types ${lhs.widenDealias} and ${rhs.widenDealias} using `!=' will always yield true " ,
121
+ tree.pos)
122
+ }
123
+ qual.select(defn.Any_== ).appliedToArgs(tree.args).select(defn.Boolean_! )
107
124
/*
108
125
/* else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) {
109
126
// todo: this is needed to support value classes
Original file line number Diff line number Diff line change
1
+
2
+ object Test {
3
+ != (1 ) // warning: comparing values of types Test and Int using `!=' will always yield true
4
+ != (" abc" ) // warning: comparing values of types Test and String using `!=' will always yield true
5
+ 1 != this // warning: comparing values of types Int and Test using `!=' will always yield true
6
+ != (this )
7
+ }
Original file line number Diff line number Diff line change
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) // warning
9
+ println(c.fullName)
10
+ c.info.toString.lines
11
+ .filter(_ != " private var bitmap$init$0: Boolean" ) foreach println
12
+ }
You can’t perform that action at this time.
0 commit comments