Skip to content

Commit 2ed2826

Browse files
committed
Strip null on the scrutinee
Without that, we end up with either a flexible type or a `| Null`.
1 parent eb90deb commit 2ed2826

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ object SpaceEngine {
835835
/** Return the underlying type of non-module, non-constant, non-enum case singleton types.
836836
* Also widen ExprType to its result type, and rewrap any annotation wrappers.
837837
* For example, with `val opt = None`, widen `opt.type` to `None.type`. */
838-
def toUnderlying(tp: Type)(using Context): Type = trace(i"toUnderlying($tp)")(tp match {
838+
def toUnderlying(tp: Type)(using Context): Type = trace(i"toUnderlying($tp ${tp.className})")(tp match {
839839
case _: ConstantType => tp
840840
case tp: TermRef if tp.symbol.is(Module) => tp
841841
case tp: TermRef if tp.symbol.isAllOf(EnumCase) => tp
@@ -846,7 +846,7 @@ object SpaceEngine {
846846
})
847847

848848
def checkExhaustivity(m: Match)(using Context): Unit = trace(i"checkExhaustivity($m)") {
849-
val selTyp = toUnderlying(m.selector.tpe).dealias
849+
val selTyp = toUnderlying(m.selector.tpe.stripNull()).dealias
850850
val targetSpace = trace(i"targetSpace($selTyp)")(project(selTyp))
851851

852852
val patternSpace = Or(m.cases.foldLeft(List.empty[Space]) { (acc, x) =>
@@ -879,7 +879,7 @@ object SpaceEngine {
879879
def checkReachability(m: Match)(using Context): Unit = trace(i"checkReachability($m)") {
880880
val cases = m.cases.toIndexedSeq
881881

882-
val selTyp = toUnderlying(m.selector.tpe).dealias
882+
val selTyp = toUnderlying(m.selector.tpe.stripNull()).dealias
883883

884884
val isNullable = selTyp.classSymbol.isNullableClass
885885
val targetSpace = trace(i"targetSpace($selTyp)")(if isNullable

tests/warn/i20132.future-Left.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -Yexplicit-nulls -Yno-flexible-types
2+
3+
import scala.language.unsafeNulls
4+
5+
import java.util.concurrent.CompletableFuture
6+
import scala.jdk.CollectionConverters._
7+
8+
class Test1:
9+
def m1 =
10+
val fut: CompletableFuture[Either[String, List[String]]] = ???
11+
fut.thenApply:
12+
case Right(edits: List[String]) => edits.asJava
13+
case Left(error: String) => throw new Exception(error)

0 commit comments

Comments
 (0)