-
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.
Handle TupleXXL in match analysis (#19212)
There's a number of problems with the match analysis of TupleXXL. Of course, they manifest as (in)exhaustivity and (un)reachability warnings. Reachability suffered by the problem that a large generic tuple scrutinee type wasn't considered extractable by the TupleXXL extractor that Typer associates the extractor pattern with. That was solved by special handling in SpaceEngine's isSubType. Exhaustivity suffered by a variety of problems, again stemming from the disconnect between the TupleXXL pattern type and the large generic tuple scrutinee (or component) type. That was solved by special handling in exhaustivityCheckable to ignore large generic tuple scrutinees. That then highlighted an irrefutable failure (checkIrrefutable), which also needed to be taught that extra large generic tuples do conform to TupleXXL extractors type, after which SpaceEngine isIrrefutable needed special handling to consider TupleXXL irrefutable.
- Loading branch information
Showing
8 changed files
with
115 additions
and
15 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,20 @@ | ||
//> using options -Werror | ||
|
||
class Test: | ||
def t1: Unit = | ||
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) match | ||
case (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23) => | ||
def t2: Unit = | ||
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23) match | ||
case (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24) => | ||
def t3: Unit = | ||
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24) match | ||
case (x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23) => | ||
|
||
object Main: | ||
def main(args: Array[String]): Unit = { | ||
val t = new Test | ||
t.t1 | ||
try { t.t2; ??? } catch case _: MatchError => () | ||
try { t.t3; ??? } catch case _: MatchError => () | ||
} |
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 @@ | ||
//> using options -Werror | ||
|
||
class Test: | ||
val x = 42 | ||
val tup23 = (x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x) | ||
|
||
tup23 match { | ||
case (_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _) => "Tuple Pattern" | ||
} |
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 -Werror | ||
|
||
class Test: | ||
val (_, ( | ||
_, _, _, _, _, _, _, _, _, _, // 10 | ||
_, _, _, _, _, _, _, _, _, _, // 20 | ||
_, c22, _ // 23 | ||
)) = // nested pattern has 23 elems | ||
(0, ( | ||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, | ||
1, 2, 3, 4, 5, 6, 7, 8, 9, 20, | ||
1, 2, 3 | ||
)) // ok, exhaustive, reachable, conforming and irrefutable |
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 @@ | ||
//> using options -Werror | ||
|
||
class Test: | ||
def t1(y: ( | ||
Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | ||
"Bob", Int, 33, Int, | ||
Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) | ||
): Unit = y match | ||
case b @ (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, | ||
"Bob", y1, 33, y2, | ||
z0, z1, z2, z3, z4, z5, z6, z7, z8, z9) | ||
=> // was: !!! spurious unreachable case warning | ||
() | ||
case _ => () |
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 @@ | ||
|
||
|
||
class Test: | ||
def t1(y: ( | ||
Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, | ||
"Bob", Int, 33, Int, | ||
Int, Int, Int, Int, Int, Int, Int, Int, Int, Int) | ||
): Unit = y match | ||
case b @ (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, | ||
"Bob", y1, 33, y2, | ||
z0, z1, z2, z3, z4, z5, z6, z7, z8, z9) | ||
=> () | ||
case b @ (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, // warn: unreachable | ||
"Bob", y1, 33, y2, | ||
z0, z1, z2, z3, z4, z5, z6, z7, z8, z9) | ||
=> () | ||
case _ => () |