Skip to content

Commit 5224871

Browse files
committed
Factor out useful Tuple map type match
1 parent 83b336e commit 5224871

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ trait Implicits { self: Typer =>
719719
// TupledFunction[?, (...) => R]
720720
tupled.dropDependentRefinement.dealias.argInfos match {
721721
case tupledArgs :: funRet :: Nil =>
722-
defn.tupleTypes(tupledArgs) match {
722+
defn.tupleTypes(tupledArgs.dealias) match {
723723
case Some(funArgs) if functionTypeEqual(tupled, funArgs, funRet, fun) =>
724724
// TupledFunction[?, ((...funArgs...)) => funRet]
725725
funArgs.size

library/src-3.x/scala/Tuple.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ object Tuple {
132132
case x *: xs => S[Size[xs]]
133133
}
134134

135+
/** Converts a tuple `(T1, ..., Tn)` to `(F[T1], ..., F[Tn])` */
136+
type Map[Tup <: Tuple, F[_]] <: Tuple = Tup match {
137+
case Unit => Unit
138+
case h *: t => F[h] *: Map[t, F]
139+
}
140+
135141
private[scala] type BoundedSizeRecur[X, L <: Int] <: Int = X match {
136142
case Unit => 0
137143
case x *: xs =>

library/src-3.x/scala/quoted/Expr.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ package quoted {
2121
def show(implicit toolbox: Toolbox): String = toolbox.show(expr)
2222
}
2323

24-
type TupleOfExpr[Tup <: Tuple] <: Tuple = Tup match {
25-
case Unit => Unit
26-
case h *: t => Expr[h] *: TupleOfExpr[t]
27-
}
24+
/** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */
25+
type TupleOfExpr[Tup <: Tuple] = Tuple.Map[Tup, Expr]
2826

2927
implicit class FunctionBetaReduction[F, Args <: Tuple, R](f: Expr[F]) given (tf: TupledFunction[F, Args => R]) {
3028
/** Beta-reduces the function appication. Generates the an expression only containing the body of the function */

0 commit comments

Comments
 (0)