Skip to content

Commit 7d7a7d1

Browse files
committed
Fix scala#4661: Missing unreachable case warnings
1 parent ab84cfb commit 7d7a7d1

File tree

1 file changed

+13
-8
lines changed
  • compiler/src/dotty/tools/dotc/transform/patmat

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,21 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
294294

295295
override def intersectUnrelatedAtomicTypes(tp1: Type, tp2: Type) = {
296296
val and = AndType(tp1, tp2)
297-
// Precondition: !(tp1 <:< tp2) && !(tp2 <:< tp1)
298-
// Then, no leaf of the and-type tree `and` is a subtype of `and`.
299-
val res = inhabited(and)
297+
// Precondition: !isSubType(tp1, tp2) && !isSubType(tp2 <:< tp1)
298+
if (tp1 == nullType || tp2 == nullType) {
299+
// Since projections of types don't include null, intersection with null is empty.
300+
Empty
301+
} else {
302+
// Then, no leaf of the and-type tree `and` is a subtype of `and`.
303+
val res = inhabited(and)
300304

301-
debug.println(s"atomic intersection: ${and.show} = ${res}")
305+
debug.println(s"atomic intersection: ${and.show} = ${res}")
302306

303-
if (!res) Empty
304-
else if (tp1.isSingleton) Typ(tp1, true)
305-
else if (tp2.isSingleton) Typ(tp2, true)
306-
else Typ(and, true)
307+
if (!res) Empty
308+
else if (tp1.isSingleton) Typ(tp1, true)
309+
else if (tp2.isSingleton) Typ(tp2, true)
310+
else Typ(and, true)
311+
}
307312
}
308313

309314
/** Whether the extractor is irrefutable */

0 commit comments

Comments
 (0)