Skip to content

Commit 634cb3d

Browse files
committed
Add warning on != with same type fix isNullable.
Note that without the fix console tests will fail and without the warning there is no way to test the fix.
1 parent 2d18af6 commit 634cb3d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
527527
}
528528
isSubType(hi1, tp2) || compareGADT
529529
case _ =>
530-
def isNullable(tp: Type): Boolean = tp.dealias match {
530+
def isNullable(tp: Type): Boolean = tp.widenDealias match {
531531
case tp: TypeRef => tp.symbol.isNullableClass
532532
case tp: RefinedOrRecType => isNullable(tp.parent)
533533
case AndType(tp1, tp2) => isNullable(tp1) && isNullable(tp2)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ class InterceptedMethods extends MiniPhaseTransform {
103103
case Any_## =>
104104
poundPoundValue(qual)
105105
case Any_!= =>
106-
qual.select(defn.Any_==).appliedToArgs(tree.args).select(defn.Boolean_!)
106+
val lhs = qual.tpe
107+
val rhs = tree.args.head.tpe
108+
if (!(lhs <:< rhs || rhs <:< lhs)) {
109+
ctx.warning(ex"comparing values of types ${lhs.widenDealias} and ${rhs.widenDealias} using `!=' will always yield true",
110+
tree.pos)
111+
}
112+
qual.select(defn.Any_==).appliedToArgs(tree.args).select(defn.Boolean_!)
107113
/*
108114
/* else if (isPrimitiveValueClass(qual.tpe.typeSymbol)) {
109115
// todo: this is needed to support value classes

0 commit comments

Comments
 (0)