Skip to content

Commit a16c3ad

Browse files
committed
WIP Fix scala#5257: Support auto generic-tupling of parameters
1 parent 7087a6c commit a16c3ad

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ class Definitions {
10741074
}
10751075

10761076
def isProductSubType(tp: Type)(implicit ctx: Context): Boolean =
1077-
tp.derivesFrom(ProductType.symbol)
1077+
tp.derivesFrom(ProductType.symbol) || tp.derivesFrom(PairClass)
10781078

10791079
/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN
10801080
* instance?

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,17 @@ object Applications {
5959
extractorMemberType(tp, nme.get, errorPos).exists
6060

6161
def productSelectorTypes(tp: Type, errorPos: Position = NoPosition)(implicit ctx: Context): List[Type] = {
62-
val sels = for (n <- Iterator.from(0)) yield extractorMemberType(tp, nme.selectorName(n), errorPos)
63-
sels.takeWhile(_.exists).toList
62+
def tupleSelectors(n: Int, tp: Type): List[Type] = {
63+
val sel = extractorMemberType(tp, nme.selectorName(n), errorPos)
64+
if (sel.exists) sel :: tupleSelectors(n + 1, tp) else Nil
65+
}
66+
def genTupleSelectors(n: Int, tp: Type): List[Type] = tp match {
67+
case tp: AppliedType if !tp.derivesFrom(defn.ProductClass) && tp.derivesFrom(defn.PairClass) =>
68+
val List(head, tail) = tp.args
69+
head :: genTupleSelectors(n, tail)
70+
case _ => tupleSelectors(n, tp)
71+
}
72+
genTupleSelectors(0, tp)
6473
}
6574

6675
def productArity(tp: Type)(implicit ctx: Context): Int =

0 commit comments

Comments
 (0)