@@ -1450,15 +1450,13 @@ object desugar {
1450
1450
sel
1451
1451
end match
1452
1452
1453
- case class TuplePatternInfo (arity : Int , varNum : Int , wildcardNum : Int , typedVarNum : Int , typedWildcardNum : Int )
1453
+ case class TuplePatternInfo (arity : Int , varNum : Int , wildcardNum : Int )
1454
1454
object TuplePatternInfo :
1455
1455
def apply (pat : Tree )(using Context ): TuplePatternInfo = pat match
1456
1456
case Tuple (pats) =>
1457
1457
var arity = 0
1458
1458
var varNum = 0
1459
1459
var wildcardNum = 0
1460
- var typedVarNum = 0
1461
- var typedWildcardNum = 0
1462
1460
pats.foreach: p =>
1463
1461
arity += 1
1464
1462
p match
@@ -1467,15 +1465,10 @@ object desugar {
1467
1465
varNum += 1
1468
1466
if id.name == nme.WILDCARD then
1469
1467
wildcardNum += 1
1470
- case Typed (id : Ident , _) if ! isBackquoted(id) =>
1471
- if id.name.isVarPattern then
1472
- typedVarNum += 1
1473
- if id.name == nme.WILDCARD then
1474
- typedWildcardNum += 1
1475
1468
case _ =>
1476
- TuplePatternInfo (arity, varNum, wildcardNum, typedVarNum, typedWildcardNum )
1469
+ TuplePatternInfo (arity, varNum, wildcardNum)
1477
1470
case _ =>
1478
- TuplePatternInfo (- 1 , - 1 , - 1 , - 1 , - 1 )
1471
+ TuplePatternInfo (- 1 , - 1 , - 1 )
1479
1472
end TuplePatternInfo
1480
1473
1481
1474
/** If `pat` is a variable pattern,
@@ -1514,7 +1507,7 @@ object desugar {
1514
1507
val tuplePatternInfo = TuplePatternInfo (pat)
1515
1508
1516
1509
// When desugaring a PatDef in general, we use pattern matching on the rhs
1517
- // and collect the variable values in a tuple, then outside the match
1510
+ // and collect the variable values in a tuple, then outside the match,
1518
1511
// we destructure the tuple to get the individual variables.
1519
1512
// We can achieve two kinds of tuple optimizations if the pattern is a tuple
1520
1513
// of simple variables or wildcards:
@@ -1524,8 +1517,8 @@ object desugar {
1524
1517
// For example: `val (x, y) = if ... then (1, "a") else (2, "b")` becomes
1525
1518
// `val $1$ = if ...; val x = $1$._1; val y = $1$._2`.
1526
1519
// 2. Partial optimization:
1527
- // If the rhs can be typed as a tuple and matched with correct arity,
1528
- // we can return the tuple itself if there are no more than one variable
1520
+ // If the rhs can be typed as a tuple and matched with correct arity, we can
1521
+ // return the tuple itself in the case if there are no more than one variable
1529
1522
// in the pattern, or return the the value if there is only one variable.
1530
1523
1531
1524
val fullTupleOptimizable =
@@ -1539,10 +1532,10 @@ object desugar {
1539
1532
1540
1533
val partialTupleOptimizable =
1541
1534
tuplePatternInfo.arity > 0
1542
- && tuplePatternInfo.arity == tuplePatternInfo.varNum + tuplePatternInfo.typedVarNum
1535
+ && tuplePatternInfo.arity == tuplePatternInfo.varNum
1543
1536
// We exclude the case where there is only one variable,
1544
1537
// because it should be handled by `makeTuple` directly.
1545
- && tuplePatternInfo.wildcardNum + tuplePatternInfo.typedWildcardNum < tuplePatternInfo.arity - 1
1538
+ && tuplePatternInfo.wildcardNum < tuplePatternInfo.arity - 1
1546
1539
1547
1540
val inAliasGenerator = original match
1548
1541
case _ : GenAlias => true
@@ -1551,10 +1544,7 @@ object desugar {
1551
1544
val vars : List [VarInfo ] =
1552
1545
if fullTupleOptimizable || partialTupleOptimizable then // include `_`
1553
1546
pat match
1554
- case Tuple (pats) => pats.map {
1555
- case id : Ident => (id, TypeTree ())
1556
- case Typed (id : Ident , tpt) => (id, tpt)
1557
- }
1547
+ case Tuple (pats) => pats.map { case id : Ident => (id, TypeTree ()) }
1558
1548
else
1559
1549
getVariables(
1560
1550
tree = pat,
@@ -1578,10 +1568,7 @@ object desugar {
1578
1568
// Replace all variables with wildcards in the pattern
1579
1569
val pat1 = pat match
1580
1570
case Tuple (pats) =>
1581
- val wildcardPats = pats.map {
1582
- case id : Ident => Ident (nme.WILDCARD ).withSpan(id.span)
1583
- case p @ Typed (_ : Ident , tpt) => Typed (Ident (nme.WILDCARD ), tpt).withSpan(p.span)
1584
- }
1571
+ val wildcardPats = pats.map(p => Ident (nme.WILDCARD ).withSpan(p.span))
1585
1572
Tuple (wildcardPats).withSpan(pat.span)
1586
1573
CaseDef (
1587
1574
Bind (tmpTuple, pat1),
@@ -1591,8 +1578,6 @@ object desugar {
1591
1578
else CaseDef (pat, EmptyTree , makeTuple(ids).withAttachment(ForArtifact , ()))
1592
1579
Match (makeSelector(rhs, MatchCheck .IrrefutablePatDef ), caseDef :: Nil )
1593
1580
1594
- // println(i"matchExpr = $matchExpr")
1595
-
1596
1581
vars match {
1597
1582
case Nil if ! mods.is(Lazy ) =>
1598
1583
matchExpr
0 commit comments