diff --git a/library/src-2.x/scala/quoted/Expr.scala b/library/src-2.x/scala/quoted/Expr.scala new file mode 100644 index 000000000000..d0efc9cfee3f --- /dev/null +++ b/library/src-2.x/scala/quoted/Expr.scala @@ -0,0 +1,49 @@ +package scala.quoted + +import scala.runtime.quoted.Unpickler.Pickled + +sealed abstract class Expr[+T] { + + /** Evaluate the contents of this expression and return the result. + * + * May throw a FreeVariableError on expressions that came from a macro. + */ + final def run(implicit toolbox: Toolbox): T = toolbox.run(this) + +} + +/** All implementations of Expr[T]. + * These should never be used directly. + */ +object Exprs { + /** An Expr backed by a pickled TASTY tree */ + final class TastyExpr[+T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] { + override def toString: String = s"Expr()" + } + + /** An Expr backed by a lifted value. + * Values can only be of type Boolean, Byte, Short, Char, Int, Long, Float, Double, Unit, String or Null. + */ + final class LiftedExpr[+T](val value: T) extends Expr[T] { + override def toString: String = s"Expr($value)" + } + + /** An Expr backed by a tree. Only the current compiler trees are allowed. + * + * These expressions are used for arguments of macros. They contain and actual tree + * from the program that is being expanded by the macro. + * + * May contain references to code defined outside this TastyTreeExpr instance. + */ + final class TastyTreeExpr[Tree](val tree: Tree) extends quoted.Expr[Any] { + override def toString: String = s"Expr()" + } + + // 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/library/src-3.x/scala/quoted/Expr.scala b/library/src-3.x/scala/quoted/Expr.scala new file mode 100644 index 000000000000..cc5bce8ee581 --- /dev/null +++ b/library/src-3.x/scala/quoted/Expr.scala @@ -0,0 +1,334 @@ +package scala.quoted + +import scala.runtime.quoted.Unpickler.Pickled + +sealed abstract class Expr[+T] { + + /** Evaluate the contents of this expression and return the result. + * + * May throw a FreeVariableError on expressions that came from a macro. + */ + final def run(implicit toolbox: Toolbox): T = toolbox.run(this) + +} + +object Expr { + + implicit class ExprOps[T](expr: Expr[T]) { + /** Show a source code like representation of this expression */ + def show(implicit toolbox: Toolbox): String = toolbox.show(expr) + } + + implicit object FunctionBetaReduction { + + /** Beta-reduces the function appication. Generates the an expression only containing the body of the function */ + def (f: Expr[() => R]) apply[R] (): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array.empty) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1) => R]) apply[T1, R](x1: Expr[T1]): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array(x1)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2) => R]) apply[T1, T2, R](x1: Expr[T1], x2: Expr[T2]): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array(x1, x2)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3) => R]) apply[T1, T2, T3, R](x1: Expr[T1], x2: Expr[T2], x3: Expr[T3]): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4) => R]) apply[T1, T2, T3, T4, R](x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4]): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5) => R]) apply[T1, T2, T3, T4, T5, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6) => R]) apply[T1, T2, T3, T4, T5, T6, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7) => R]) apply[T1, T2, T3, T4, T5, T6, T7, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](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)) + + /** Beta-reduces the function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (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]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](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)) + + } + + implicit object ContextualFunctionBetaReduction { + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1) => R]) apply[T1, R](x1: Expr[T1]): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array(x1)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2) => R]) apply[T1, T2, R](x1: Expr[T1], x2: Expr[T2]): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array(x1, x2)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3) => R]) apply[T1, T2, T3, R](x1: Expr[T1], x2: Expr[T2], x3: Expr[T3]): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4) => R]) apply[T1, T2, T3, T4, R](x1: Expr[T1], x2: Expr[T2], x3: Expr[T3], x4: Expr[T4]): Expr[R] = + new Exprs.FunctionAppliedTo[R](f, Array(x1, x2, x3, x4)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5) => R]) apply[T1, T2, T3, T4, T5, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6) => R]) apply[T1, T2, T3, T4, T5, T6, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7) => R]) apply[T1, T2, T3, T4, T5, T6, T7, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, R](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)) + + /** Beta-reduces the contextual function appication. + * Generates the an expression that evaluates all arguments and then evaluates the body with the evaluated arguments + */ + def (f: Expr[given (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => R]) apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, R](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)) + + } + +} + +/** All implementations of Expr[T]. + * These should never be used directly. + */ +object Exprs { + /** An Expr backed by a pickled TASTY tree */ + final class TastyExpr[+T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] { + override def toString: String = s"Expr()" + } + + /** An Expr backed by a lifted value. + * Values can only be of type Boolean, Byte, Short, Char, Int, Long, Float, Double, Unit, String or Null. + */ + final class LiftedExpr[+T](val value: T) extends Expr[T] { + override def toString: String = s"Expr($value)" + } + + /** An Expr backed by a tree. Only the current compiler trees are allowed. + * + * These expressions are used for arguments of macros. They contain and actual tree + * from the program that is being expanded by the macro. + * + * May contain references to code defined outside this TastyTreeExpr instance. + */ + final class TastyTreeExpr[Tree](val tree: Tree) extends quoted.Expr[Any] { + override def toString: String = s"Expr()" + } + + // 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/library/src/scala/quoted/Expr.scala b/library/src/scala/quoted/Expr.scala deleted file mode 100644 index 79259718051c..000000000000 --- a/library/src/scala/quoted/Expr.scala +++ /dev/null @@ -1,152 +0,0 @@ -package scala.quoted - -import scala.runtime.quoted.Unpickler.Pickled - -sealed abstract class Expr[+T] { - - /** Evaluate the contents of this expression and return the result. - * - * May throw a FreeVariableError on expressions that came from a macro. - */ - final def run(implicit toolbox: Toolbox): T = toolbox.run(this) - -} - -object Expr { - - // TODO simplify using new extension methods - - implicit class ExprOps[T](expr: Expr[T]) { - /** Show a source code like representation of this expression */ - def show(implicit toolbox: Toolbox): String = toolbox.show(expr) - } - - 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)) - } - -} - -/** All implementations of Expr[T]. - * These should never be used directly. - */ -object Exprs { - /** An Expr backed by a pickled TASTY tree */ - final class TastyExpr[+T](val tasty: Pickled, val args: Seq[Any]) extends Expr[T] { - override def toString: String = s"Expr()" - } - - /** An Expr backed by a lifted value. - * Values can only be of type Boolean, Byte, Short, Char, Int, Long, Float, Double, Unit, String or Null. - */ - final class LiftedExpr[+T](val value: T) extends Expr[T] { - override def toString: String = s"Expr($value)" - } - - /** An Expr backed by a tree. Only the current compiler trees are allowed. - * - * These expressions are used for arguments of macros. They contain and actual tree - * from the program that is being expanded by the macro. - * - * May contain references to code defined outside this TastyTreeExpr instance. - */ - final class TastyTreeExpr[Tree](val tree: Tree) extends quoted.Expr[Any] { - override def toString: String = s"Expr()" - } - - // 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 index 3f3b0dfcd836..814c7af6efce 100644 --- a/tests/run-with-compiler/quote-function-applied-to.check +++ b/tests/run-with-compiler/quote-function-applied-to.check @@ -318,3 +318,322 @@ Test.x(0) 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) } +{ + 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 index daa9b8f308ee..8720ff612417 100644 --- a/tests/run-with-compiler/quote-function-applied-to.scala +++ b/tests/run-with-compiler/quote-function-applied-to.scala @@ -26,6 +26,29 @@ object Test { 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) + + println(('{ given (x1: Int) => x1 }).apply('{x(1)}).show) + println(('{ given (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}).show) + println(('{ given (x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 }).apply('{x(1)}, '{x(2)}, '{x(3)}).show) + println(('{ given (x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}).show) + println(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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(('{ given (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