Skip to content

Commit 68a988a

Browse files
dwijnandWojciechMazur
authored andcommitted
Strip null in exhaustivityCheckable
1 parent a3abf27 commit 68a988a

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

Lines changed: 6 additions & 4 deletions
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.*
@@ -801,12 +803,12 @@ object SpaceEngine {
801803
doShow(s)
802804
}
803805

804-
private def exhaustivityCheckable(sel: Tree)(using Context): Boolean = {
806+
private def exhaustivityCheckable(sel: Tree)(using Context): Boolean = trace(i"exhaustivityCheckable($sel ${sel.className})") {
805807
val seen = collection.mutable.Set.empty[Symbol]
806808

807809
// Possible to check everything, but be compatible with scalac by default
808-
def isCheckable(tp: Type): Boolean =
809-
val tpw = tp.widen.dealias
810+
def isCheckable(tp: Type): Boolean = trace(i"isCheckable($tp ${tp.className})"):
811+
val tpw = tp.widen.dealias.stripNull()
810812
val classSym = tpw.classSymbol
811813
classSym.is(Sealed) && !tpw.isLargeGenericTuple || // exclude large generic tuples from exhaustivity
812814
// requires an unknown number of changes to make work

tests/warn/i20132.stream-Tuple2.scala

Lines changed: 18 additions & 0 deletions
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)