Skip to content

Commit e501845

Browse files
committed
Warn about nonsensical isInstanceOf tests with Nothing as the scrutinee type
1 parent 1c42de7 commit e501845

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ object TypeTestsCasts {
247247
if expr.tpe.isNotNull then constant(expr, Literal(Constant(true)))
248248
else expr.testNotNull
249249
else {
250+
if expr.tpe.isBottomType then
251+
report.warning(TypeTestAlwaysDiverges(expr.tpe, testType), tree.srcPos)
250252
val nestedCtx = ctx.fresh.setNewTyperState()
251253
val foundClsSyms = foundClasses(expr.tpe.widen, Nil)
252254
val sensical = checkSensical(foundClsSyms)(using nestedCtx)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val n = Nil
2+
val b = n.head.isInstanceOf[String] // error
3+

0 commit comments

Comments
 (0)