-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bundle of patmat issues (#21000)
- Loading branch information
Showing
22 changed files
with
289 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
sealed trait NatT | ||
case class Zero() extends NatT | ||
case class Succ[+N <: NatT](n: N) extends NatT | ||
|
||
type Mod2[N <: NatT] <: NatT = N match | ||
case Zero => Zero | ||
case Succ[Zero] => Succ[Zero] | ||
case Succ[Succ[predPredN]] => Mod2[predPredN] | ||
|
||
def dependentlyTypedMod2[N <: NatT](n: N): Mod2[N] = n match | ||
case Zero(): Zero => Zero() // warn | ||
case Succ(Zero()): Succ[Zero] => Succ(Zero()) // warn | ||
case Succ(Succ(predPredN)): Succ[Succ[?]] => dependentlyTypedMod2(predPredN) // warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
sealed trait T_A[A, B] | ||
type X = T_A[Byte, Byte] | ||
|
||
case class CC_B[A](a: A) extends T_A[A, X] | ||
|
||
val v_a: T_A[X, X] = CC_B(null) | ||
val v_b = v_a match | ||
case CC_B(_) => 0 // warn: unreachable | ||
case _ => 1 | ||
// for CC_B[A] to match T_A[X, X] | ||
// A := X | ||
// so require X, aka T_A[Byte, Byte] | ||
// which isn't instantiable, outside of null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
sealed trait T_B[C, D] | ||
|
||
case class CC_A() | ||
case class CC_B[A, C](a: A) extends T_B[C, CC_A] | ||
case class CC_C[C, D](a: T_B[C, D]) extends T_B[Int, CC_A] | ||
case class CC_E(a: CC_C[Char, Byte]) | ||
|
||
val v_a: T_B[Int, CC_A] = CC_B(CC_E(CC_C(null))) | ||
val v_b = v_a match | ||
case CC_B(CC_E(CC_C(_))) => 0 // warn: unreachable | ||
case _ => 1 | ||
// for CC_B[A, C] to match T_B[C, CC_A] | ||
// C <: Int, ok | ||
// A <: CC_E, ok | ||
// but you need a CC_C[Char, Byte] | ||
// which requires a T_B[Char, Byte] | ||
// which isn't instantiable, outside of null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
sealed trait T_A[A, B] | ||
sealed trait T_B[C] | ||
|
||
case class CC_D[A, C]() extends T_A[A, C] | ||
case class CC_E() extends T_B[Nothing] | ||
case class CC_G[A, C](c: C) extends T_A[A, C] | ||
|
||
val v_a: T_A[Boolean, T_B[Boolean]] = CC_G(null) | ||
val v_b = v_a match { | ||
case CC_D() => 0 | ||
case CC_G(_) => 1 // warn: unreachable | ||
// for CC_G[A, C] to match T_A[Boolean, T_B[Boolean]] | ||
// A := Boolean, which is ok | ||
// C := T_B[Boolean], | ||
// which isn't instantiable, outside of null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sealed trait T_A[A] | ||
case class CC_B[A](a: T_A[A]) extends T_A[Byte] | ||
case class CC_E[A](b: T_A[A]) extends T_A[Byte] | ||
|
||
val v_a: T_A[Byte] = CC_E(CC_B(null)) | ||
val v_b: Int = v_a match { // warn: not exhaustive | ||
case CC_E(CC_E(_)) => 0 | ||
case CC_B(_) => 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
sealed trait T_A[A] | ||
case class CC_B[A](a: T_A[A], c: T_A[A]) extends T_A[Char] | ||
case class CC_C[A]() extends T_A[A] | ||
case class CC_G() extends T_A[Char] | ||
|
||
val v_a: T_A[Char] = CC_B(CC_G(), CC_C()) | ||
val v_b: Int = v_a match { // warn: not exhaustive | ||
case CC_C() => 0 | ||
case CC_G() => 1 | ||
case CC_B(CC_B(_, _), CC_C()) => 2 | ||
case CC_B(CC_C(), CC_C()) => 3 | ||
case CC_B(_, CC_G()) => 4 | ||
case CC_B(_, CC_B(_, _)) => 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
sealed trait T_A[B] | ||
sealed trait T_B[C] | ||
case class CC_B[C]() extends T_A[T_B[C]] | ||
case class CC_C[B, C](c: T_A[B], d: T_B[C]) extends T_B[C] | ||
case class CC_E[C]() extends T_B[C] | ||
|
||
val v_a: T_B[Int] = CC_C(null, CC_E()) | ||
val v_b: Int = v_a match { // warn: not exhaustive | ||
case CC_C(_, CC_C(_, _)) => 0 | ||
case CC_E() => 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
sealed trait Foo | ||
case class Foo1() extends Foo | ||
case class Foo2[A, B]() extends Foo | ||
|
||
sealed trait Bar[A, B] | ||
case class Bar1[A, C, D](a: Bar[C, D]) extends Bar[A, Bar[C, D]] | ||
case class Bar2[ C, D](b: Bar[C, D], c: Foo) extends Bar[Bar1[Int, Byte, Int], Bar[C, D]] | ||
|
||
class Test: | ||
def m1(bar: Bar[Bar1[Int, Byte, Int], Bar[Char, Char]]): Int = bar match | ||
case Bar1(_) => 0 | ||
case Bar2(_, Foo2()) => 1 | ||
def t1 = m1(Bar2(null, Foo1())) | ||
// for Bar2[C, D] to match the scrutinee | ||
// C := Char and D := Char | ||
// which requires a Bar[Char, Char] | ||
// which isn't instantiable, outside of null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sealed trait Foo[A] | ||
case class Bar[C](x: Foo[C]) extends Foo[C] | ||
case class End[B]() extends Foo[B] | ||
class Test: | ||
def m1[M](foo: Foo[M]): Int = foo match // warn: not exhaustive | ||
case End() => 0 | ||
case Bar(End()) => 1 | ||
def t1 = m1[Int](Bar[Int](Bar[Int](End[Int]()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//> using options -Yexplicit-nulls -Yno-flexible-types | ||
|
||
import scala.language.unsafeNulls | ||
|
||
import java.util.concurrent.CompletableFuture | ||
import scala.jdk.CollectionConverters._ | ||
|
||
class Test1: | ||
def m1 = | ||
val fut: CompletableFuture[Either[String, List[String]]] = ??? | ||
fut.thenApply: | ||
case Right(edits: List[String]) => edits.asJava | ||
case Left(error: String) => throw new Exception(error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class D1 | ||
class D2 | ||
|
||
class Test1: | ||
type Ds = List[D1] | List[D2] | ||
def m1(dss: List[Ds]) = | ||
dss.flatMap: | ||
case Seq(d) => Some(1) | ||
case Seq(head, tail*) => Some(2) | ||
case Seq() => None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sealed trait Foo[A] | ||
case class Bar[C](x: Foo[C]) extends Foo[Int] | ||
case class End[B]() extends Foo[B] | ||
class Test: | ||
def m1[M](foo: Foo[M]): Int = foo match // warn: not exhaustive | ||
case End() => 0 | ||
case Bar(End()) => 1 | ||
def t1 = m1[Int](Bar[Int](Bar[Int](End[Int]()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- [E029] Pattern Match Exhaustivity Warning: tests/warn/i20132.stream-Tuple2.safeNulls.scala:8:24 --------------------- | ||
8 | xs.asJava.forEach { case (a, b) => // warn | ||
| ^ | ||
| match may not be exhaustive. | ||
| | ||
| It would fail on pattern case: _: Null | ||
| | ||
| longer explanation available when compiling with `-explain` |
Oops, something went wrong.