Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public enum ErrorMessageID {
DoubleDeclarationID,
MatchCaseOnlyNullWarningID,
ImportRenamedTwiceID,
TypeTestAlwaysSucceedsID,
;

public int errorNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2117,4 +2117,9 @@ object messages {
val explanation: String = ""
}

case class TypeTestAlwaysSucceeds(foundCls: Symbol, testCls: Symbol)(implicit ctx: Context) extends Message(TypeTestAlwaysSucceedsID) {
val kind = "Syntax"
val msg = s"The highlighted type test will always succeed since the scrutinee type ($foundCls) is a subtype of ${testCls}"
val explanation = ""
}
}
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ValueClasses._
import SymUtils._
import core.Flags._
import util.Positions._
import reporting.diagnostic.messages.TypeTestAlwaysSucceeds
import reporting.trace


Expand Down Expand Up @@ -90,9 +91,7 @@ object TypeTestsCasts {

if (expr.tpe <:< testType)
if (expr.tpe.isNotNull) {
ctx.warning(
em"this will always yield true, since `$foundCls` is a subclass of `$testCls`",
expr.pos)
ctx.warning(TypeTestAlwaysSucceeds(foundCls, testCls), tree.pos)
constant(expr, Literal(Constant(true)))
}
else expr.testNotNull
Expand Down