Skip to content

Commit 1cad96a

Browse files
committed
Fix #4674: Do not emit waring if types are the same
1 parent 1b73ba6 commit 1cad96a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

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

9292
if (expr.tpe <:< testType)
9393
if (expr.tpe.isNotNull) {
94-
ctx.warning(TypeTestAlwaysSucceeds(foundCls, testCls), tree.pos)
94+
if (foundCls != testCls)
95+
ctx.warning(TypeTestAlwaysSucceeds(foundCls, testCls), tree.pos)
9596
constant(expr, Literal(Constant(true)))
9697
}
9798
else expr.testNotNull
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Foo {
2+
def foo: Unit = {
3+
val x: String = "something"
4+
x.foreach {
5+
case 's' => println("s")
6+
case c: Char => println(c) // no warn for `: Char` allways succeeding
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)