Skip to content

Commit 9f8c089

Browse files
committed
Fix false warning about unreachable code in Dotty
1 parent 9d1e94c commit 9f8c089

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,14 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
509509
case space => List(space)
510510
}
511511
case OrType(tp1, tp2) => List(Typ(tp1, true), Typ(tp2, true))
512-
case _ if tp =:= ctx.definitions.BooleanType =>
512+
case tp if tp =:= ctx.definitions.BooleanType =>
513513
List(
514514
Typ(ConstantType(Constant(true)), true),
515515
Typ(ConstantType(Constant(false)), true)
516516
)
517-
case _ if tp.classSymbol.is(Enum) =>
517+
case tp if tp.classSymbol.is(Enum) =>
518518
children.map(sym => Typ(sym.termRef, true))
519-
case _ =>
519+
case tp =>
520520
val parts = children.map { sym =>
521521
if (sym.is(ModuleClass))
522522
refine(tp, sym.sourceModule.termRef)

tests/patmat/dotty-unreachable.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object Types {
2+
abstract case class TermRef(val prefix: String, name: String) {
3+
type ThisType = TermRef
4+
5+
def alts: List[TermRef] = ???
6+
}
7+
}
8+
9+
class Test {
10+
def foo(tp: Types.TermRef): Unit = {
11+
tp.alts.filter(_.name == "apply") match {
12+
case Nil =>
13+
case alt :: Nil =>
14+
case alt =>
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)