@@ -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 ._
@@ -329,15 +329,16 @@ object PatternMatcher {
329
329
def isSyntheticScala2Unapply (sym : Symbol ) =
330
330
sym.isAllOf(SyntheticCase ) && sym.owner.is(Scala2x )
331
331
332
+ def tupleApp (i : Int , receiver : Tree ) = // manually inlining the call to NonEmptyTuple#apply, because it's an inline method
333
+ ref(defn.RuntimeTuplesModule )
334
+ .select(defn.RuntimeTuples_apply )
335
+ .appliedTo(receiver, Literal (Constant (i)))
336
+ .cast(args(i).tpe.widen)
337
+
332
338
if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
333
339
def tupleSel (sym : Symbol ) = ref(scrutinee).select(sym)
334
- def tupleApp (i : Int ) = // manually inlining the call to NonEmptyTuple#apply, because it's an inline method
335
- ref(defn.RuntimeTuplesModule )
336
- .select(defn.RuntimeTuples_apply )
337
- .appliedTo(ref(scrutinee), Literal (Constant (i)))
338
- .cast(args(i).tpe.widen)
339
340
val isGenericTuple = defn.isTupleClass(caseClass) && ! defn.isTupleNType(tree.tpe)
340
- val components = if isGenericTuple then caseAccessors.indices.toList.map(tupleApp) else caseAccessors.map(tupleSel)
341
+ val components = if isGenericTuple then caseAccessors.indices.toList.map(tupleApp(_, ref(scrutinee)) ) else caseAccessors.map(tupleSel)
341
342
matchArgsPlan(components, args, onSuccess)
342
343
else if (unapp.tpe <:< (defn.BooleanType ))
343
344
TestPlan (GuardTest , unapp, unapp.span, onSuccess)
@@ -349,6 +350,9 @@ object PatternMatcher {
349
350
.map(ref(unappResult).select(_))
350
351
matchArgsPlan(selectors, args, onSuccess)
351
352
}
353
+ else if unappResult.info <:< defn.NonEmptyTupleTypeRef then
354
+ val components = (0 until foldApplyTupleType(unappResult.denot.info).length).toList.map(tupleApp(_, ref(unappResult)))
355
+ matchArgsPlan(components, args, onSuccess)
352
356
else if (isUnapplySeq && isProductSeqMatch(unapp.tpe.widen, args.length, unapp.srcPos)) {
353
357
val arity = productArity(unapp.tpe.widen, unapp.srcPos)
354
358
unapplyProductSeqPlan(unappResult, args, arity)
0 commit comments