@@ -1450,15 +1450,13 @@ object desugar {
14501450 sel
14511451 end match
14521452
1453- case class TuplePatternInfo (arity : Int , varNum : Int , wildcardNum : Int , typedVarNum : Int , typedWildcardNum : Int )
1453+ case class TuplePatternInfo (arity : Int , varNum : Int , wildcardNum : Int )
14541454 object TuplePatternInfo :
14551455 def apply (pat : Tree )(using Context ): TuplePatternInfo = pat match
14561456 case Tuple (pats) =>
14571457 var arity = 0
14581458 var varNum = 0
14591459 var wildcardNum = 0
1460- var typedVarNum = 0
1461- var typedWildcardNum = 0
14621460 pats.foreach: p =>
14631461 arity += 1
14641462 p match
@@ -1467,15 +1465,10 @@ object desugar {
14671465 varNum += 1
14681466 if id.name == nme.WILDCARD then
14691467 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
14751468 case _ =>
1476- TuplePatternInfo (arity, varNum, wildcardNum, typedVarNum, typedWildcardNum )
1469+ TuplePatternInfo (arity, varNum, wildcardNum)
14771470 case _ =>
1478- TuplePatternInfo (- 1 , - 1 , - 1 , - 1 , - 1 )
1471+ TuplePatternInfo (- 1 , - 1 , - 1 )
14791472 end TuplePatternInfo
14801473
14811474 /** If `pat` is a variable pattern,
@@ -1514,7 +1507,7 @@ object desugar {
15141507 val tuplePatternInfo = TuplePatternInfo (pat)
15151508
15161509 // 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,
15181511 // we destructure the tuple to get the individual variables.
15191512 // We can achieve two kinds of tuple optimizations if the pattern is a tuple
15201513 // of simple variables or wildcards:
@@ -1524,8 +1517,8 @@ object desugar {
15241517 // For example: `val (x, y) = if ... then (1, "a") else (2, "b")` becomes
15251518 // `val $1$ = if ...; val x = $1$._1; val y = $1$._2`.
15261519 // 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
15291522 // in the pattern, or return the the value if there is only one variable.
15301523
15311524 val fullTupleOptimizable =
@@ -1539,10 +1532,10 @@ object desugar {
15391532
15401533 val partialTupleOptimizable =
15411534 tuplePatternInfo.arity > 0
1542- && tuplePatternInfo.arity == tuplePatternInfo.varNum + tuplePatternInfo.typedVarNum
1535+ && tuplePatternInfo.arity == tuplePatternInfo.varNum
15431536 // We exclude the case where there is only one variable,
15441537 // because it should be handled by `makeTuple` directly.
1545- && tuplePatternInfo.wildcardNum + tuplePatternInfo.typedWildcardNum < tuplePatternInfo.arity - 1
1538+ && tuplePatternInfo.wildcardNum < tuplePatternInfo.arity - 1
15461539
15471540 val inAliasGenerator = original match
15481541 case _ : GenAlias => true
@@ -1551,10 +1544,7 @@ object desugar {
15511544 val vars : List [VarInfo ] =
15521545 if fullTupleOptimizable || partialTupleOptimizable then // include `_`
15531546 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 ()) }
15581548 else
15591549 getVariables(
15601550 tree = pat,
@@ -1578,10 +1568,7 @@ object desugar {
15781568 // Replace all variables with wildcards in the pattern
15791569 val pat1 = pat match
15801570 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))
15851572 Tuple (wildcardPats).withSpan(pat.span)
15861573 CaseDef (
15871574 Bind (tmpTuple, pat1),
@@ -1591,8 +1578,6 @@ object desugar {
15911578 else CaseDef (pat, EmptyTree , makeTuple(ids).withAttachment(ForArtifact , ()))
15921579 Match (makeSelector(rhs, MatchCheck .IrrefutablePatDef ), caseDef :: Nil )
15931580
1594- // println(i"matchExpr = $matchExpr")
1595-
15961581 vars match {
15971582 case Nil if ! mods.is(Lazy ) =>
15981583 matchExpr
0 commit comments