diff --git a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala index 98096d13d86b..2eb28cda5b06 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala @@ -47,8 +47,8 @@ object PickledQuotes { case value => Literal(Constant(value)) } case expr: TastyTreeExpr[Tree] @unchecked => healOwner(expr.tree) - case expr: FunctionAppliedTo[_, _] => - functionAppliedTo(quotedExprToTree(expr.f), quotedExprToTree(expr.x)) + case expr: FunctionAppliedTo[_] => + functionAppliedTo(quotedExprToTree(expr.f), expr.args.map(arg => quotedExprToTree(arg)).toList) } /** Transform the expression into its fully spliced TypeTree */ @@ -127,26 +127,27 @@ object PickledQuotes { TypeTree(tpe) } - private def functionAppliedTo(f: Tree, x: Tree)(implicit ctx: Context): Tree = { - val x1 = SyntheticValDef(NameKinds.UniqueName.fresh("x".toTermName), x) - def x1Ref() = ref(x1.symbol) - def rec(f: Tree): Tree = f match { + private def functionAppliedTo(fn: Tree, args: List[Tree])(implicit ctx: Context): Tree = { + val argVals = args.map(arg => SyntheticValDef(NameKinds.UniqueName.fresh("x".toTermName), arg)) + def argRefs() = argVals.map(argVal => ref(argVal.symbol)) + def rec(fn: Tree): Tree = fn match { case Inlined(call, bindings, expansion) => // this case must go before closureDef to avoid dropping the inline node - cpy.Inlined(f)(call, bindings, rec(expansion)) + cpy.Inlined(fn)(call, bindings, rec(expansion)) case closureDef(ddef) => - val paramSym = ddef.vparamss.head.head.symbol + val paramSyms = ddef.vparamss.head.map(param => param.symbol) + val paramToVals = paramSyms.zip(argRefs()).toMap new TreeTypeMap( oldOwners = ddef.symbol :: Nil, newOwners = ctx.owner :: Nil, - treeMap = tree => if (tree.symbol == paramSym) x1Ref().withPos(tree.pos) else tree + treeMap = tree => paramToVals.get(tree.symbol).map(_.withPos(tree.pos)).getOrElse(tree) ).transform(ddef.rhs) case Block(stats, expr) => seq(stats, rec(expr)) case _ => - f.select(nme.apply).appliedTo(x1Ref()) + fn.select(nme.apply).appliedToArgs(argRefs()) } - Block(x1 :: Nil, rec(f)) + Block(argVals, rec(fn)) } private def classToType(clazz: Class[_])(implicit ctx: Context): Type = { diff --git a/docs/docs/reference/principled-meta-programming.md b/docs/docs/reference/principled-meta-programming.md index 79d46a2ab5d6..44490b16843a 100644 --- a/docs/docs/reference/principled-meta-programming.md +++ b/docs/docs/reference/principled-meta-programming.md @@ -130,26 +130,26 @@ PCP. This is explained further in a later section. ### From `Expr`s to Functions and Back -The `Expr` companion object contains an "AsFunction" decorator that turns a tree +The `Expr` companion object contains an `AsFunctionN` (for 0 <= N < 23) decorator that turns a tree describing a function into a function mapping trees to trees. object Expr { ... - implicit class AsFunction[T, U](f: Expr[T => U]) extends AnyVal { + implicit class AsFunction1[T, U](f: Expr[T => U]) extends AnyVal { def apply(x: Expr[T]): Expr[U] = ??? } } This decorator gives `Expr` the `apply` operation of an applicative functor, where `Expr`s over function types can be applied to `Expr` arguments. The definition -of `AsFunction(f).apply(x)` is assumed to be functionally the same as +of `AsFunction1(f).apply(x)` is assumed to be functionally the same as `'((~f)(~x))`, however it should optimize this call by returning the -result of beta-reducing `f(x)` if `f` is a known lambda expression +result of beta-reducing `f(x)` if `f` is a known lambda expression. -The `AsFunction` decorator distributes applications of `Expr` over function +The `AsFunction1` decorator distributes applications of `Expr` over function arrows: - AsFunction(_).apply: Expr[S => T] => (Expr[S] => Expr[T]) + AsFunction1(_).apply: Expr[S => T] => (Expr[S] => Expr[T]) Its dual, let’s call it `reflect`, can be defined as follows: diff --git a/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala index 5368d9e632b5..eda1fb984802 100644 --- a/library/src/scala/quoted/Expr.scala +++ b/library/src/scala/quoted/Expr.scala @@ -20,8 +20,98 @@ object Expr { def apply[T](x: T): Expr[T] = throw new Error("Internal error: this method call should have been replaced by the compiler") - implicit class AsFunction[T, U](private val f: Expr[T => U]) extends AnyVal { - def apply(x: Expr[T]): Expr[U] = new Exprs.FunctionAppliedTo[T, U](f, x) + // TODO simplify using new extension methods + + implicit class AsFunction0[R](private val f: Expr[() => R]) extends AnyVal { + def apply(): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array.empty) + } + + implicit class AsFunction1[T1, R](private val f: Expr[(T1) => R]) extends AnyVal { + def apply(x1: Expr[T1]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1)) + } + + implicit class AsFunction2[T1, T2, R](private val f: Expr[(T1, T2) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2)) + } + + implicit class AsFunction3[T1, T2, T3, R](private val f: Expr[(T1, T2, T3) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3)) + } + + implicit class AsFunction4[T1, T2, T3, T4, R](private val f: Expr[(T1, T2, T3, T4) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4)) + } + + implicit class AsFunction5[T1, T2, T3, T4, T5, R](private val f: Expr[(T1, T2, T3, T4, T5) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5)) + } + + implicit class AsFunction6[T1, T2, T3, T4, T5, T6, R](private val f: Expr[(T1, T2, T3, T4, T5, T6) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6)) + } + + implicit class AsFunction7[T1, T2, T3, T4, T5, T6, T7, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7)) + } + + implicit class AsFunction8[T1, T2, T3, T4, T5, T6, T7, T8, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8)) + } + + implicit class AsFunction9[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9)) + } + + implicit class AsFunction10[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)) + } + + implicit class AsFunction11[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11)) + } + + implicit class AsFunction12[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12)) + } + + implicit class AsFunction13[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13)) + } + + implicit class AsFunction14[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14)) + } + + implicit class AsFunction15[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14], x15: Expr[T15]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15)) + } + + implicit class AsFunction16[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14], x15: Expr[T15], x16: Expr[T16]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16)) + } + + implicit class AsFunction17[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14], x15: Expr[T15], x16: Expr[T16], x17: Expr[T17]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17)) + } + + implicit class AsFunction18[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14], x15: Expr[T15], x16: Expr[T16], x17: Expr[T17], x18: Expr[T18]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18)) + } + + implicit class AsFunction19[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14], x15: Expr[T15], x16: Expr[T16], x17: Expr[T17], x18: Expr[T18], x19: Expr[T19]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19)) + } + + implicit class AsFunction20[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14], x15: Expr[T15], x16: Expr[T16], x17: Expr[T17], x18: Expr[T18], x19: Expr[T19], x20: Expr[T20]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20)) + } + + implicit class AsFunction21[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14], x15: Expr[T15], x16: Expr[T16], x17: Expr[T17], x18: Expr[T18], x19: Expr[T19], x20: Expr[T20], x21: Expr[T21]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21)) + } + + implicit class AsFunction22[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](private val f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R]) extends AnyVal { + def apply(x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4], x5: Expr[T5], x6: Expr[T6], x7: Expr[T7], x8: Expr[T8], x9: Expr[T9], x10: Expr[T10], x11: Expr[T11], x12: Expr[T12], x13: Expr[T13], x14: Expr[T14], x15: Expr[T15], x16: Expr[T16], x17: Expr[T17], x18: Expr[T18], x19: Expr[T19], x20: Expr[T20], x21: Expr[T21], x22: Expr[T22]): Expr[R] = new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22)) } } @@ -53,8 +143,11 @@ object Exprs { override def toString: String = s"Expr()" } - /** An Expr representing `'{(~f).apply(~x)}` but it is beta-reduced when the closure is known */ - final class FunctionAppliedTo[T, +U](val f: Expr[T => U], val x: Expr[T]) extends Expr[U] { - override def toString: String = s"Expr($f $x)" + // TODO Use a List in FunctionAppliedTo(val f: Expr[_], val args: List[Expr[_]]) + // FIXME: Having the List in the code above trigers an assertion error while testing dotty.tools.dotc.reporting.ErrorMessagesTests.i3187 + // This test does redefine `scala.collection`. Further investigation is needed. + /** An Expr representing `'{(~f).apply(~x1, ..., ~xn)}` but it is beta-reduced when the closure is known */ + final class FunctionAppliedTo[+R](val f: Expr[_], val args: Array[Expr[_]]) extends Expr[R] { + override def toString: String = s"Expr($f ${args.toList})" } } diff --git a/tests/run-with-compiler/quote-function-applied-to.check b/tests/run-with-compiler/quote-function-applied-to.check new file mode 100644 index 000000000000..3f3b0dfcd836 --- /dev/null +++ b/tests/run-with-compiler/quote-function-applied-to.check @@ -0,0 +1,320 @@ +Test.x(0) +{ + val x$1: scala.Int = Test.x(1) + x$1 +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + x$1.+(x$2) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + x$1.+(x$2).+(x$3) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + x$1.+(x$2).+(x$3).+(x$4) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + x$1.+(x$2).+(x$3).+(x$4).+(x$5) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + val x$15: scala.Int = Test.x(15) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14).+(x$15) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + val x$15: scala.Int = Test.x(15) + val x$16: scala.Int = Test.x(16) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14).+(x$15).+(x$16) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + val x$15: scala.Int = Test.x(15) + val x$16: scala.Int = Test.x(16) + val x$17: scala.Int = Test.x(17) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14).+(x$15).+(x$16).+(x$17) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + val x$15: scala.Int = Test.x(15) + val x$16: scala.Int = Test.x(16) + val x$17: scala.Int = Test.x(17) + val x$18: scala.Int = Test.x(18) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14).+(x$15).+(x$16).+(x$17).+(x$18) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + val x$15: scala.Int = Test.x(15) + val x$16: scala.Int = Test.x(16) + val x$17: scala.Int = Test.x(17) + val x$18: scala.Int = Test.x(18) + val x$19: scala.Int = Test.x(19) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14).+(x$15).+(x$16).+(x$17).+(x$18).+(x$19) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + val x$15: scala.Int = Test.x(15) + val x$16: scala.Int = Test.x(16) + val x$17: scala.Int = Test.x(17) + val x$18: scala.Int = Test.x(18) + val x$19: scala.Int = Test.x(19) + val x$20: scala.Int = Test.x(20) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14).+(x$15).+(x$16).+(x$17).+(x$18).+(x$19).+(x$20) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + val x$15: scala.Int = Test.x(15) + val x$16: scala.Int = Test.x(16) + val x$17: scala.Int = Test.x(17) + val x$18: scala.Int = Test.x(18) + val x$19: scala.Int = Test.x(19) + val x$20: scala.Int = Test.x(20) + val x$21: scala.Int = Test.x(21) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14).+(x$15).+(x$16).+(x$17).+(x$18).+(x$19).+(x$20).+(x$21) +} +{ + val x$1: scala.Int = Test.x(1) + val x$2: scala.Int = Test.x(2) + val x$3: scala.Int = Test.x(3) + val x$4: scala.Int = Test.x(4) + val x$5: scala.Int = Test.x(5) + val x$6: scala.Int = Test.x(6) + val x$7: scala.Int = Test.x(7) + val x$8: scala.Int = Test.x(8) + val x$9: scala.Int = Test.x(9) + val x$10: scala.Int = Test.x(10) + val x$11: scala.Int = Test.x(11) + val x$12: scala.Int = Test.x(12) + val x$13: scala.Int = Test.x(13) + val x$14: scala.Int = Test.x(14) + val x$15: scala.Int = Test.x(15) + val x$16: scala.Int = Test.x(16) + val x$17: scala.Int = Test.x(17) + val x$18: scala.Int = Test.x(18) + val x$19: scala.Int = Test.x(19) + val x$20: scala.Int = Test.x(20) + val x$21: scala.Int = Test.x(21) + val x$22: scala.Int = Test.x(22) + x$1.+(x$2).+(x$3).+(x$4).+(x$5).+(x$6).+(x$7).+(x$8).+(x$9).+(x$10).+(x$11).+(x$12).+(x$13).+(x$14).+(x$15).+(x$16).+(x$17).+(x$18).+(x$19).+(x$20).+(x$21).+(x$22) +} diff --git a/tests/run-with-compiler/quote-function-applied-to.scala b/tests/run-with-compiler/quote-function-applied-to.scala new file mode 100644 index 000000000000..faac3dfec8a6 --- /dev/null +++ b/tests/run-with-compiler/quote-function-applied-to.scala @@ -0,0 +1,32 @@ +import quoted._ +import scala.quoted.Toolbox.Default._ + +object Test { + def main(args: Array[String]): Unit = { + println(('{ () => x(0) }).apply().show) + println(('{ (x1: Int) => x1 }).apply('(x(1))).show) + println(('{ (x1: Int, x2: Int) => x1 + x2 }).apply('(x(1)), '(x(2))).show) + println(('{ (x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 }).apply('(x(1)), '(x(2)), '(x(3))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int) => x1 + x2 + x3 + x4 + x5 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int) => x1 + x2 + x3 + x4 + x5 + x6 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14)), '(x(15))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14)), '(x(15)), '(x(16))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14)), '(x(15)), '(x(16)), '(x(17))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14)), '(x(15)), '(x(16)), '(x(17)), '(x(18))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14)), '(x(15)), '(x(16)), '(x(17)), '(x(18)), '(x(19))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14)), '(x(15)), '(x(16)), '(x(17)), '(x(18)), '(x(19)), '(x(20))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14)), '(x(15)), '(x(16)), '(x(17)), '(x(18)), '(x(19)), '(x(20)), '(x(21))).show) + println(('{ (x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int, x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int, x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int, x22: Int) => x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20 + x21 + x22 }).apply('(x(1)), '(x(2)), '(x(3)), '(x(4)), '(x(5)), '(x(6)), '(x(7)), '(x(8)), '(x(9)), '(x(10)), '(x(11)), '(x(12)), '(x(13)), '(x(14)), '(x(15)), '(x(16)), '(x(17)), '(x(18)), '(x(19)), '(x(20)), '(x(21)), '(x(22))).show) + } + + def x(i: Int): Int = i +}