Skip to content

Commit

Permalink
WIP Fix scala#5257: Support auto generic-tupling of parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Oct 15, 2018
1 parent 7087a6c commit a16c3ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Expand Up @@ -1074,7 +1074,7 @@ class Definitions {
}

def isProductSubType(tp: Type)(implicit ctx: Context): Boolean =
tp.derivesFrom(ProductType.symbol)
tp.derivesFrom(ProductType.symbol) || tp.derivesFrom(PairClass)

/** Is `tp` (an alias) of either a scala.FunctionN or a scala.ImplicitFunctionN
* instance?
Expand Down
13 changes: 11 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Expand Up @@ -59,8 +59,17 @@ object Applications {
extractorMemberType(tp, nme.get, errorPos).exists

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

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

0 comments on commit a16c3ad

Please sign in to comment.