Skip to content

Commit 8df91fa

Browse files
committed
Strip null in exhaustivityCheckable
1 parent 7183bb2 commit 8df91fa

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package dotc
33
package transform
44
package patmat
55

6-
import core.*, Constants.*, Contexts.*, Decorators.*, Flags.*, Names.*, NameOps.*, StdNames.*, Symbols.*, Types.*
6+
import core.*
7+
import Constants.*, Contexts.*, Decorators.*, Flags.*, NullOpsDecorator.*, Symbols.*, Types.*
8+
import Names.*, NameOps.*, StdNames.*
79
import ast.*, tpd.*
810
import config.Printers.*
911
import printing.{ Printer, * }, Texts.*
@@ -793,12 +795,12 @@ object SpaceEngine {
793795
doShow(s)
794796
}
795797

796-
private def exhaustivityCheckable(sel: Tree)(using Context): Boolean = {
798+
private def exhaustivityCheckable(sel: Tree)(using Context): Boolean = trace(i"exhaustivityCheckable($sel ${sel.className})") {
797799
val seen = collection.mutable.Set.empty[Symbol]
798800

799801
// Possible to check everything, but be compatible with scalac by default
800-
def isCheckable(tp: Type): Boolean =
801-
val tpw = tp.widen.dealias
802+
def isCheckable(tp: Type): Boolean = trace(i"isCheckable($tp ${tp.className})"):
803+
val tpw = tp.widen.dealias.stripNull()
802804
val classSym = tpw.classSymbol
803805
classSym.is(Sealed) && !tpw.isLargeGenericTuple || // exclude large generic tuples from exhaustivity
804806
// requires an unknown number of changes to make work

tests/warn/i20132.stream-Tuple2.scala

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//> using options -Yexplicit-nulls -Yno-flexible-types
2+
3+
// Previously failed because the scrutinee under
4+
// unsafeNulls/explicit-nulls/no-flexible-types
5+
// is (String, String) | Null
6+
// Need to strip the null before considering it exhaustivity checkable
7+
8+
import scala.language.unsafeNulls
9+
10+
import scala.jdk.CollectionConverters.*
11+
12+
class Test2:
13+
def t1: Unit = {
14+
val xs = List.empty[(String, String)]
15+
xs.asJava.forEach { case (a, b) =>
16+
()
17+
}
18+
}

0 commit comments

Comments
 (0)