Skip to content

Commit becafe4

Browse files
committed
Closes scala#4300 adds better worded pattern match unreachability warning
- Used when isInstanceOf is called inside a match case - The new message is "this case will always be taken because the scrutinee has type `<type>`" - Highlights the position of `x: Int` instead of `x`
1 parent def8b69 commit becafe4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,14 @@ object TypeTestsCasts {
9090

9191
if (expr.tpe <:< testType)
9292
if (expr.tpe.isNotNull) {
93-
ctx.warning(
94-
em"this will always yield true, since `$foundCls` is a subclass of `$testCls`",
95-
expr.pos)
93+
if (inMatch)
94+
ctx.warning(
95+
em"this case will always be taken because the scrutinee has type `$testType`",
96+
tree.pos)
97+
else
98+
ctx.warning(
99+
em"this will always yield true, since `$foundCls` is a subclass of `$testCls`",
100+
expr.pos)
96101
constant(expr, Literal(Constant(true)))
97102
}
98103
else expr.testNotNull

0 commit comments

Comments
 (0)