Skip to content

Commit 93a5ccc

Browse files
committed
Fix #4674: Improve error message
1 parent 1cad96a commit 93a5ccc

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,12 @@ object messages {
20972097

20982098
case class TypeTestAlwaysSucceeds(foundCls: Symbol, testCls: Symbol)(implicit ctx: Context) extends Message(TypeTestAlwaysSucceedsID) {
20992099
val kind = "Syntax"
2100-
val msg = s"The highlighted type test will always succeed since the scrutinee type ($foundCls) is a subtype of ${testCls}"
2100+
val msg = {
2101+
val addendum =
2102+
if (foundCls != testCls) s" is a subtype of $testCls"
2103+
else " is the same as the tested type"
2104+
s"The highlighted type test will always succeed since the scrutinee type ($foundCls)" + addendum
2105+
}
21012106
val explanation = ""
21022107
}
21032108
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ object TypeTestsCasts {
9191

9292
if (expr.tpe <:< testType)
9393
if (expr.tpe.isNotNull) {
94-
if (foundCls != testCls)
95-
ctx.warning(TypeTestAlwaysSucceeds(foundCls, testCls), tree.pos)
94+
ctx.warning(TypeTestAlwaysSucceeds(foundCls, testCls), tree.pos)
9695
constant(expr, Literal(Constant(true)))
9796
}
9897
else expr.testNotNull

tests/pos-special/fatal-warnings/i4674.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)