@@ -8,7 +8,7 @@ import collection.mutable
8
8
import Symbols ._ , Contexts ._ , Types ._ , StdNames ._ , NameOps ._
9
9
import ast .Trees ._
10
10
import util .Spans ._
11
- import typer .Applications .{ isProductMatch , isGetMatch , isProductSeqMatch , productSelectors , productArity , unapplySeqTypeElemTp }
11
+ import typer .Applications .*
12
12
import SymUtils ._
13
13
import Flags ._ , Constants ._
14
14
import Decorators ._
@@ -325,15 +325,16 @@ object PatternMatcher {
325
325
def isSyntheticScala2Unapply (sym : Symbol ) =
326
326
sym.isAllOf(SyntheticCase ) && sym.owner.is(Scala2x )
327
327
328
+ def tupleApp (i : Int , receiver : Tree ) = // manually inlining the call to NonEmptyTuple#apply, because it's an inline method
329
+ ref(defn.RuntimeTuplesModule )
330
+ .select(defn.RuntimeTuples_apply )
331
+ .appliedTo(receiver, Literal (Constant (i)))
332
+ .cast(args(i).tpe.widen)
333
+
328
334
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
329
335
def tupleSel (sym : Symbol ) = ref(scrutinee).select(sym)
330
- def tupleApp (i : Int ) = // manually inlining the call to NonEmptyTuple#apply, because it's an inline method
331
- ref(defn.RuntimeTuplesModule )
332
- .select(defn.RuntimeTuples_apply )
333
- .appliedTo(ref(scrutinee), Literal (Constant (i)))
334
- .cast(args(i).tpe.widen)
335
336
val isGenericTuple = defn.isTupleClass(caseClass) && ! defn.isTupleNType(tree.tpe)
336
- val components = if isGenericTuple then caseAccessors.indices.toList.map(tupleApp) else caseAccessors.map(tupleSel)
337
+ val components = if isGenericTuple then caseAccessors.indices.toList.map(tupleApp(_, ref(scrutinee)) ) else caseAccessors.map(tupleSel)
337
338
matchArgsPlan(components, args, onSuccess)
338
339
else if (unapp.tpe <:< (defn.BooleanType ))
339
340
TestPlan (GuardTest , unapp, unapp.span, onSuccess)
@@ -345,6 +346,9 @@ object PatternMatcher {
345
346
.map(ref(unappResult).select(_))
346
347
matchArgsPlan(selectors, args, onSuccess)
347
348
}
349
+ else if unappResult.info <:< defn.NonEmptyTupleTypeRef then
350
+ val components = (0 until foldApplyTupleType(unappResult.denot.info).length).toList.map(tupleApp(_, ref(unappResult)))
351
+ matchArgsPlan(components, args, onSuccess)
348
352
else if (isUnapplySeq && isProductSeqMatch(unapp.tpe.widen, args.length, unapp.srcPos)) {
349
353
val arity = productArity(unapp.tpe.widen, unapp.srcPos)
350
354
unapplyProductSeqPlan(unappResult, args, arity)
0 commit comments