Skip to content

Commit 51362d8

Browse files
Support generic tuples as a valid unapplySeq return type
1 parent ac43086 commit 51362d8

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,16 @@ object PatternMatcher {
346346
.map(ref(unappResult).select(_))
347347
matchArgsPlan(selectors, args, onSuccess)
348348
}
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)
352349
else if (isUnapplySeq && isProductSeqMatch(unapp.tpe.widen, args.length, unapp.srcPos)) {
353350
val arity = productArity(unapp.tpe.widen, unapp.srcPos)
354351
unapplyProductSeqPlan(unappResult, args, arity)
355352
}
356353
else if (isUnapplySeq && unapplySeqTypeElemTp(unapp.tpe.widen.finalResultType).exists) {
357354
unapplySeqPlan(unappResult, args)
358355
}
356+
else if unappResult.info <:< defn.NonEmptyTupleTypeRef then
357+
val components = (0 until foldApplyTupleType(unappResult.denot.info).length).toList.map(tupleApp(_, ref(unappResult)))
358+
matchArgsPlan(components, args, onSuccess)
359359
else {
360360
assert(isGetMatch(unapp.tpe))
361361
val argsPlan = {

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ object Applications {
173173
val elemTp = unapplySeqTypeElemTp(tp)
174174
if (elemTp.exists) args.map(Function.const(elemTp))
175175
else if (isProductSeqMatch(tp, args.length, pos)) productSeqSelectors(tp, args.length, pos)
176+
else if tp.derivesFrom(defn.NonEmptyTupleClass) then foldApplyTupleType(tp)
176177
else fallback
177178
}
178179

0 commit comments

Comments
 (0)