Skip to content

Commit

Permalink
Strip null in exhaustivityCheckable
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jul 4, 2024
1 parent 8ad49d0 commit 79c6341
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package dotc
package transform
package patmat

import core.*, Constants.*, Contexts.*, Decorators.*, Flags.*, Names.*, NameOps.*, StdNames.*, Symbols.*, Types.*
import core.*
import Constants.*, Contexts.*, Decorators.*, Flags.*, NullOpsDecorator.*, Symbols.*, Types.*
import Names.*, NameOps.*, StdNames.*
import ast.*, tpd.*
import config.Printers.*
import printing.{ Printer, * }, Texts.*
Expand Down Expand Up @@ -793,12 +795,12 @@ object SpaceEngine {
doShow(s)
}

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

// Possible to check everything, but be compatible with scalac by default
def isCheckable(tp: Type): Boolean =
val tpw = tp.widen.dealias
def isCheckable(tp: Type): Boolean = trace(i"isCheckable($tp ${tp.className})"):
val tpw = tp.widen.dealias.stripNull()
val classSym = tpw.classSymbol
classSym.is(Sealed) && !tpw.isLargeGenericTuple || // exclude large generic tuples from exhaustivity
// requires an unknown number of changes to make work
Expand Down
18 changes: 18 additions & 0 deletions tests/warn/i20132.stream-Tuple2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//> using options -Yexplicit-nulls -Yno-flexible-types

// Previously failed because the scrutinee under
// unsafeNulls/explicit-nulls/no-flexible-types
// is (String, String) | Null
// Need to strip the null before considering it exhaustivity checkable

import scala.language.unsafeNulls

import scala.jdk.CollectionConverters.*

class Test2:
def t1: Unit = {
val xs = List.empty[(String, String)]
xs.asJava.forEach { case (a, b) =>
()
}
}

0 comments on commit 79c6341

Please sign in to comment.