@@ -8,7 +8,7 @@ import collection.mutable
88import Symbols ._ , Contexts ._ , Types ._ , StdNames ._ , NameOps ._
99import ast .Trees ._
1010import util .Spans ._
11- import typer .Applications .{ isProductMatch , isGetMatch , isProductSeqMatch , productSelectors , productArity , unapplySeqTypeElemTp }
11+ import typer .Applications .*
1212import SymUtils ._
1313import Flags ._ , Constants ._
1414import Decorators ._
@@ -325,15 +325,16 @@ object PatternMatcher {
325325 def isSyntheticScala2Unapply (sym : Symbol ) =
326326 sym.isAllOf(SyntheticCase ) && sym.owner.is(Scala2x )
327327
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+
328334 if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length)
329335 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)
335336 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)
337338 matchArgsPlan(components, args, onSuccess)
338339 else if (unapp.tpe <:< (defn.BooleanType ))
339340 TestPlan (GuardTest , unapp, unapp.span, onSuccess)
@@ -345,6 +346,9 @@ object PatternMatcher {
345346 .map(ref(unappResult).select(_))
346347 matchArgsPlan(selectors, args, onSuccess)
347348 }
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)
348352 else if (isUnapplySeq && isProductSeqMatch(unapp.tpe.widen, args.length, unapp.srcPos)) {
349353 val arity = productArity(unapp.tpe.widen, unapp.srcPos)
350354 unapplyProductSeqPlan(unappResult, args, arity)
0 commit comments