diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index 21952c83832b..b05be940b584 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit 21952c83832b1fdaa31e97314a8ac7fa28b737aa +Subproject commit b05be940b58440ee9dcf38f584f3283fc1d01799 diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 6d345a1550cc..f0d6177e09b0 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -773,6 +773,7 @@ class Definitions { @threadUnsafe lazy val InternalQuoted_patternHoleR: TermRef = InternalQuotedModule.requiredMethodRef("patternHole") def InternalQuoted_patternHole(implicit ctx: Context): Symbol = InternalQuoted_patternHoleR.symbol @threadUnsafe lazy val InternalQuoted_patternBindHoleAnnot: ClassSymbol = InternalQuotedModule.requiredClass("patternBindHole") + @threadUnsafe lazy val InternalQuoted_QuoteTypeTagAnnot: ClassSymbol = InternalQuotedModule.requiredClass("quoteTypeTag") @threadUnsafe lazy val InternalQuotedMatcherModuleRef: TermRef = ctx.requiredModuleRef("scala.internal.quoted.Matcher") def InternalQuotedMatcherModule(implicit ctx: Context): Symbol = InternalQuotedMatcherModuleRef.symbol diff --git a/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala b/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala index 0dffbb82b7a3..de5d7a65cb2f 100644 --- a/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala +++ b/compiler/src/dotty/tools/dotc/quoted/ExprCompilationUnit.scala @@ -3,9 +3,7 @@ package dotty.tools.dotc.quoted import dotty.tools.dotc.CompilationUnit import dotty.tools.dotc.util.NoSource -import scala.quoted.Expr +import scala.quoted._ /* Compilation unit containing the contents of a quoted expression */ -class ExprCompilationUnit(val expr: Expr[_]) extends CompilationUnit(NoSource) { - override def toString: String = s"Expr($expr)" -} +class ExprCompilationUnit(val exprBuilder: QuoteContext => Expr[_]) extends CompilationUnit(NoSource) diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala index 490b11f683ad..0a5ae5672c5e 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala @@ -14,20 +14,26 @@ import dotty.tools.dotc.core.StdNames.nme import dotty.tools.dotc.core.Symbols.defn import dotty.tools.dotc.core.Types.ExprType import dotty.tools.dotc.core.quoted.PickledQuotes +import dotty.tools.dotc.tastyreflect.ReflectionImpl import dotty.tools.dotc.transform.Staging import dotty.tools.dotc.util.Spans.Span import dotty.tools.dotc.util.SourceFile import dotty.tools.io.{Path, VirtualFile} -import scala.quoted.{Expr, Type} +import scala.annotation.tailrec +import scala.concurrent.Promise +import scala.quoted.{Expr, QuoteContext, Type} /** Compiler that takes the contents of a quoted expression `expr` and produces * a class file with `class ' { def apply: Object = expr }`. */ class QuoteCompiler extends Compiler { + /** Either `Left` with name of the classfile generated or `Right` with the value contained in the expression */ + private[this] var result: Either[String, Any] = null + override protected def frontendPhases: List[List[Phase]] = - List(List(new QuotedFrontend(putInClass = true))) + List(List(new QuotedFrontend)) override protected def picklerPhases: List[List[Phase]] = List(List(new Staging)) @@ -40,58 +46,67 @@ class QuoteCompiler extends Compiler { def outputClassName: TypeName = "Generated$Code$From$Quoted".toTypeName /** Frontend that receives a scala.quoted.Expr or scala.quoted.Type as input */ - class QuotedFrontend(putInClass: Boolean) extends Phase { + class QuotedFrontend extends Phase { import tpd._ + def phaseName: String = "quotedFrontend" override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = { - units.map { + units.flatMap { case exprUnit: ExprCompilationUnit => - val tree = - if (putInClass) inClass(exprUnit.expr) - else PickledQuotes.quotedExprToTree(exprUnit.expr) - val source = SourceFile.virtual("", "") - CompilationUnit(source, tree, forceTrees = true) - case typeUnit: TypeCompilationUnit => - assert(!putInClass) - val tree = PickledQuotes.quotedTypeToTree(typeUnit.tpe) - val source = SourceFile.virtual("", "") - CompilationUnit(source, tree, forceTrees = true) + val pos = Span(0) + val assocFile = new VirtualFile("") + + // Places the contents of expr in a compilable tree for a class with the following format. + // `package __root__ { class ' { def apply: Any = } }` + val cls = ctx.newCompleteClassSymbol(defn.RootClass, outputClassName, EmptyFlags, + defn.ObjectType :: Nil, newScope, coord = pos, assocFile = assocFile).entered.asClass + cls.enter(ctx.newDefaultConstructor(cls), EmptyScope) + val meth = ctx.newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered + + val quoted = PickledQuotes.quotedExprToTree(checkValidRunExpr(exprUnit.exprBuilder.apply(new QuoteContext(ReflectionImpl(ctx)))))(ctx.withOwner(meth)) + + getLiteral(quoted) match { + case Some(value) => + result = Right(value) + None // Stop copilation here we already have the result + case None => + val run = DefDef(meth, quoted) + val classTree = ClassDef(cls, DefDef(cls.primaryConstructor.asTerm), run :: Nil) + val tree = PackageDef(ref(defn.RootPackage).asInstanceOf[Ident], classTree :: Nil).withSpan(pos) + val source = SourceFile.virtual("", "") + result = Left(outputClassName.toString) + Some(CompilationUnit(source, tree, forceTrees = true)) + } } } - /** Places the contents of expr in a compilable tree for a class - * with the following format. - * `package __root__ { class ' { def apply: Any = } }` - */ - private def inClass(expr: Expr[_])(implicit ctx: Context): Tree = { - val pos = Span(0) - val assocFile = new VirtualFile("") - - val cls = ctx.newCompleteClassSymbol(defn.RootClass, outputClassName, EmptyFlags, - defn.ObjectType :: Nil, newScope, coord = pos, assocFile = assocFile).entered.asClass - cls.enter(ctx.newDefaultConstructor(cls), EmptyScope) - val meth = ctx.newSymbol(cls, nme.apply, Method, ExprType(defn.AnyType), coord = pos).entered - - val quoted = PickledQuotes.quotedExprToTree(expr)(ctx.withOwner(meth)) + private def checkValidRunExpr(expr: Expr[_]): Expr[_] = expr match { + case expr: scala.internal.quoted.TastyTreeExpr[Tree] @unchecked => + throw new Exception("Cannot call `Expr.run` on an `Expr` that comes from a macro argument.") + case _ => expr + } - val run = DefDef(meth, quoted) - val classTree = ClassDef(cls, DefDef(cls.primaryConstructor.asTerm), run :: Nil) - PackageDef(ref(defn.RootPackage).asInstanceOf[Ident], classTree :: Nil).withSpan(pos) + /** Get the literal value if this tree only contains a literal tree */ + @tailrec private def getLiteral(tree: Tree): Option[Any] = tree match { + case Literal(lit) => Some(lit.value) + case Block(Nil, expr) => getLiteral(expr) + case Inlined(_, Nil, expr) => getLiteral(expr) + case _ => None } def run(implicit ctx: Context): Unit = unsupported("run") } - class ExprRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) { - def compileExpr(expr: Expr[_]): Unit = { - val units = new ExprCompilationUnit(expr) :: Nil - compileUnits(units) - } - def compileType(tpe: Type[_]): Unit = { - val units = new TypeCompilationUnit(tpe) :: Nil + class ExprRun(comp: QuoteCompiler, ictx: Context) extends Run(comp, ictx) { + /** Unpickle and optionally compile the expression. + * Returns either `Left` with name of the classfile generated or `Right` with the value contained in the expression. + */ + def compileExpr(exprBuilder: QuoteContext => Expr[_]): Either[String, Any] = { + val units = new ExprCompilationUnit(exprBuilder) :: Nil compileUnits(units) + result } } } diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDecompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDecompiler.scala deleted file mode 100644 index 431df7aba75f..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDecompiler.scala +++ /dev/null @@ -1,19 +0,0 @@ -package dotty.tools.dotc.quoted - -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.Contexts.Context -import dotty.tools.dotc.core.Phases.Phase - -/** Compiler that takes the contents of a quoted expression (or type) and outputs it's tree. */ -class QuoteDecompiler(output: tpd.Tree => Context => Unit) extends QuoteCompiler { - override def phases: List[List[Phase]] = List( - List(new QuotedFrontend(putInClass = false)), // Create class from Expr - List(new RefreshNames), - List(new QuoteTreeOutput(output)) - ) - - class QuoteTreeOutput(output: tpd.Tree => Context => Unit) extends Phase { - override def phaseName: String = "quoteOutput" - override def run(implicit ctx: Context): Unit = output(ctx.compilationUnit.tpdTree)(ctx) - } -} diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala index adddbb7d94d9..aea4151c3969 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala @@ -7,7 +7,7 @@ import dotty.tools.dotc.tastyreflect.ReflectionImpl import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, VirtualDirectory} import dotty.tools.repl.AbstractFileClassLoader import dotty.tools.dotc.reporting._ -import scala.quoted.{Expr, Type} +import scala.quoted._ import scala.quoted.Toolbox import java.net.URLClassLoader @@ -20,7 +20,7 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { private[this] val contextBase: ContextBase = new ContextBase - def run[T](expr: Expr[T], settings: Toolbox.Settings): T = { + def run[T](exprBuilder: QuoteContext => Expr[T], settings: Toolbox.Settings): T = { val outDir: AbstractFile = settings.outDir match { case Some(out) => val dir = Directory(out) @@ -33,56 +33,21 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { val (_, ctx0: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh) val ctx = setToolboxSettings(ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir), settings) - val driver = new QuoteCompiler - driver.newRun(ctx).compileExpr(expr) + new QuoteCompiler().newRun(ctx).compileExpr(exprBuilder) match { + case Right(value) => + value.asInstanceOf[T] - assert(!ctx.reporter.hasErrors) + case Left(classname) => + assert(!ctx.reporter.hasErrors) - val classLoader = new AbstractFileClassLoader(outDir, appClassloader) + val classLoader = new AbstractFileClassLoader(outDir, appClassloader) - val clazz = classLoader.loadClass(driver.outputClassName.toString) - val method = clazz.getMethod("apply") - val inst = clazz.getConstructor().newInstance() + val clazz = classLoader.loadClass(classname) + val method = clazz.getMethod("apply") + val inst = clazz.getConstructor().newInstance() - method.invoke(inst).asInstanceOf[T] - } - - private def doShow(tree: Tree, ctx: Context): String = { - implicit val c: Context = ctx - val tree1 = - if (ctx.settings.YshowRawQuoteTrees.value) tree - else (new TreeCleaner).transform(tree) - ReflectionImpl.showTree(tree1) - } - - def show(expr: Expr[_], settings: Toolbox.Settings): String = - withTree(expr, doShow, settings) - - def show(tpe: Type[_], settings: Toolbox.Settings): String = - withTypeTree(tpe, doShow, settings) - - def withTree[T](expr: Expr[_], f: (Tree, Context) => T, settings: Toolbox.Settings): T = { - val ctx = setToolboxSettings(setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)._2.fresh, settings) - - var output: Option[T] = None - def registerTree(tree: tpd.Tree)(ctx: Context): Unit = { - assert(output.isEmpty) - output = Some(f(tree, ctx)) - } - new QuoteDecompiler(registerTree).newRun(ctx).compileExpr(expr) - output.getOrElse(throw new Exception("Could not extract " + expr)) - } - - def withTypeTree[T](tpe: Type[_], f: (TypTree, Context) => T, settings: Toolbox.Settings): T = { - val ctx = setToolboxSettings(setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)._2.fresh, settings) - - var output: Option[T] = None - def registerTree(tree: tpd.Tree)(ctx: Context): Unit = { - assert(output.isEmpty) - output = Some(f(tree.asInstanceOf[TypTree], ctx)) + method.invoke(inst).asInstanceOf[T] } - new QuoteDecompiler(registerTree).newRun(ctx).compileType(tpe) - output.getOrElse(throw new Exception("Could not extract " + tpe)) } override def initCtx: Context = { @@ -92,7 +57,6 @@ class QuoteDriver(appClassloader: ClassLoader) extends Driver { } private def setToolboxSettings(ctx: FreshContext, settings: Toolbox.Settings): ctx.type = { - ctx.setSetting(ctx.settings.color, if (settings.color) "always" else "never") ctx.setSetting(ctx.settings.YshowRawQuoteTrees, settings.showRawTree) // An error in the generated code is a bug in the compiler // Setting the throwing reporter however will report any exception diff --git a/compiler/src/dotty/tools/dotc/quoted/RefreshNames.scala b/compiler/src/dotty/tools/dotc/quoted/RefreshNames.scala deleted file mode 100644 index 4b00eb00079e..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/RefreshNames.scala +++ /dev/null @@ -1,38 +0,0 @@ -package dotty.tools.dotc.quoted - -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.Contexts.Context -import dotty.tools.dotc.core.DenotTransformers.SymTransformer -import dotty.tools.dotc.core.Flags._ -import dotty.tools.dotc.core.NameKinds.{NumberedInfo, UniqueName} -import dotty.tools.dotc.core.SymDenotations.SymDenotation -import dotty.tools.dotc.transform.MegaPhase.MiniPhase - -/** Refreshes local names starting from the second use of the name. Intended for readability of the pretty printed code. */ -class RefreshNames extends MiniPhase with SymTransformer { - - def phaseName: String = "RefreshNames" - - override def transformValDef(tree: tpd.ValDef)(implicit ctx: Context): tpd.Tree = - tpd.ValDef(tree.symbol.asTerm, tree.rhs) - - override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context): tpd.Tree = - tpd.DefDef(tree.symbol.asTerm, tree.rhs) - - override def transformTypeDef(tree: tpd.TypeDef)(implicit ctx: Context): tpd.Tree = { - val newTypeDef = tpd.TypeDef(tree.symbol.asType) - // keep rhs to keep `type T = ...` instead of `type T >: ... <: ...` - cpy.TypeDef(newTypeDef)(rhs = tree.rhs) - } - - def transformSym(ref: SymDenotation)(implicit ctx: Context): SymDenotation = { - if (ref.is(Package) || ref.isClass || ref.owner != ctx.owner || ref.is(Param)) ref - else { - val newName = UniqueName.fresh(ref.symbol.name.toTermName) - newName.info match { - case info: NumberedInfo if info.num == 1 => ref // Keep the first reference as is to avoid renaming if the code has no duplicated names - case _ => ref.copySymDenotation(name = if (ref.symbol.isType) newName.toTypeName else newName) - } - } - } -} diff --git a/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala b/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala index 2e11424b4b38..9e2f934040ea 100644 --- a/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala +++ b/compiler/src/dotty/tools/dotc/quoted/ToolboxImpl.scala @@ -1,13 +1,9 @@ package dotty.tools.dotc.quoted -import dotty.tools.dotc.ast.tpd - import scala.quoted._ -import scala.internal.quoted.{LiftedExpr, TastyTreeExpr} /** Default runners for quoted expressions */ object ToolboxImpl { - import tpd._ /** Create a new instance of the toolbox using the the classloader of the application. * @@ -19,18 +15,10 @@ object ToolboxImpl { private[this] val driver: QuoteDriver = new QuoteDriver(appClassloader) - def run[T](expr: Expr[T]): T = expr match { - case expr: LiftedExpr[T] => - expr.value - case expr: TastyTreeExpr[Tree] @unchecked => - throw new Exception("Cannot call `Expr.run` on an `Expr` that comes from a macro argument.") - case _ => - synchronized(driver.run(expr, settings)) + def run[T](exprBuilder: QuoteContext => Expr[T]): T = synchronized { + driver.run(exprBuilder, settings) } - def show[T](expr: Expr[T]): String = synchronized(driver.show(expr, settings)) - - def show[T](tpe: Type[T]): String = synchronized(driver.show(tpe, settings)) } } diff --git a/compiler/src/dotty/tools/dotc/quoted/TreeCleaner.scala b/compiler/src/dotty/tools/dotc/quoted/TreeCleaner.scala deleted file mode 100644 index 93c203fffb12..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/TreeCleaner.scala +++ /dev/null @@ -1,49 +0,0 @@ -package dotty.tools.dotc.quoted - -import dotty.tools.dotc.ast.Trees._ -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.Contexts._ -import dotty.tools.dotc.core.Constants._ -import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.core.Types._ - -/** Clean up quote artifacts from the tree to make it simpler to read. - * - Flattens block and remove blocks with not statements - * - Inline type aliases in the tree - */ -class TreeCleaner extends tpd.TreeMap { - import tpd._ - - /** List of symbols and their types for type aliases `type T = U` */ - private[this] var aliasesSyms: List[Symbol] = Nil - private[this] var aliasesTypes: List[Type] = Nil - private[this] val aliases = newMutableSymbolMap[Tree] - - override def transform(tree: Tree)(implicit ctx: Context): Tree = { - val tree0 = tree match { - case TypeDef(_, TypeBoundsTree(lo, hi)) if lo == hi => - aliasesSyms = tree.symbol :: aliasesSyms - aliasesTypes = lo.tpe :: aliasesTypes - aliases(tree.symbol) = ref(lo.tpe.typeSymbol) - Literal(Constant(())) - case _ => tree - } - - super.transform(tree0) match { - case Block(Nil, expr1) => expr1 - case Block(stats1, expr1) => - val flatStats = stats1.flatMap { - case Block(stats2, expr2) => stats2 ::: expr2 :: Nil - case Literal(Constant(())) => Nil - case stat => stat :: Nil - } - expr1 match { - case Block(stats3, expr3) => seq(flatStats ::: stats3, expr3) - case expr3 => seq(flatStats, expr3) - } - case tree1: TypeTree => TypeTree(tree1.tpe.subst(aliasesSyms, aliasesTypes)) - case tree1: Ident => aliases.get(tree1.symbol).getOrElse(tree1) - case tree1 => tree1 - } - } -} diff --git a/compiler/src/dotty/tools/dotc/quoted/TypeCompilationUnit.scala b/compiler/src/dotty/tools/dotc/quoted/TypeCompilationUnit.scala deleted file mode 100644 index 725e6e366a27..000000000000 --- a/compiler/src/dotty/tools/dotc/quoted/TypeCompilationUnit.scala +++ /dev/null @@ -1,11 +0,0 @@ -package dotty.tools.dotc.quoted - -import dotty.tools.dotc.CompilationUnit -import dotty.tools.dotc.util.NoSource - -import scala.quoted.Type - -/* Compilation unit containing the contents of a quoted type */ -class TypeCompilationUnit(val tpe: Type[_]) extends CompilationUnit(NoSource) { - override def toString: String = s"Type($tpe)" -} diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 6877fb22c450..7afe4afea413 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -35,12 +35,6 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Context_source(self: Context): java.nio.file.Path = self.compilationUnit.source.file.jpath - def Context_printColors(self: Context): Boolean = self.settings.color.value(self) == "always" - - def Context_withColors(self: Context): Context = ctx.fresh.setSetting(ctx.settings.color, "always") - - def Context_withoutColors(self: Context): Context = ctx.fresh.setSetting(ctx.settings.color, "never") - // // REPORTING // diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala index e6a5d9a6a84d..a529b69ff751 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionImpl.scala @@ -4,6 +4,8 @@ import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core._ import dotty.tools.dotc.util.{SourcePosition, Spans} +import scala.quoted.show.SyntaxHighlight + object ReflectionImpl { def apply(rootContext: Contexts.Context): scala.tasty.Reflection = @@ -16,7 +18,10 @@ object ReflectionImpl { val refl = new scala.tasty.Reflection(new KernelImpl(ctx, tree.sourcePos)) val reflCtx = ctx.asInstanceOf[refl.Context] val reflTree = tree.asInstanceOf[refl.Tree] - new refl.SourceCodePrinter().showTree(reflTree)(reflCtx) + val syntaxHighlight = + if (ctx.settings.color.value == "always") SyntaxHighlight.ANSI + else SyntaxHighlight.plain + new refl.SourceCodePrinter(syntaxHighlight).showTree(reflTree)(reflCtx) } } diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 4e506dfd7864..37e44fc63b52 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -19,6 +19,7 @@ import dotty.tools.dotc.ast.tpd import typer.Implicits.SearchFailureType import scala.collection.mutable +import dotty.tools.dotc.core.Annotations.Annotation import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.core.quoted._ import dotty.tools.dotc.transform.TreeMapWithStages._ @@ -115,9 +116,9 @@ class ReifyQuotes extends MacroTransform { /** Assuming contains types `${}, ..., ${}`, the expression * - * { type = ${} + * { @quoteTypeTag type = ${} * ... - * type = ${} + * @quoteTypeTag type = ${} * * } * @@ -137,7 +138,7 @@ class ReifyQuotes extends MacroTransform { flags = Synthetic, info = TypeAlias(splicedTree.tpe.select(tpnme.splice)), coord = spliced.termSymbol.coord).asType - + local.addAnnotation(Annotation(defn.InternalQuoted_QuoteTypeTagAnnot)) ctx.typeAssigner.assignType(untpd.TypeDef(local.name, alias), local) } diff --git a/compiler/src/dotty/tools/dotc/util/NameTransformer.scala b/compiler/src/dotty/tools/dotc/util/NameTransformer.scala index 8e88509f58b3..f66a8675d261 100644 --- a/compiler/src/dotty/tools/dotc/util/NameTransformer.scala +++ b/compiler/src/dotty/tools/dotc/util/NameTransformer.scala @@ -4,7 +4,7 @@ package util import core.Names._ import collection.mutable -import scala.tasty.util.Chars +import scala.internal.Chars import scala.annotation.internal.sharable diff --git a/compiler/test-resources/repl-macros/i6007 b/compiler/test-resources/repl-macros/i6007 index 4f3d9dfafa1f..ebc605750515 100644 --- a/compiler/test-resources/repl-macros/i6007 +++ b/compiler/test-resources/repl-macros/i6007 @@ -2,7 +2,7 @@ scala> implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(ge def toolbox: quoted.Toolbox scala> val v = '{ (if true then Some(1) else None).map(v => v+1) } val v: quoted.Expr[Option[Int]] = Expr() -scala> v.show +scala> scala.quoted.withQuoteContext(v.show) val res0: String = (if (true) scala.Some.apply[scala.Int](1) else scala.None).map[scala.Int](((v: scala.Int) => v.+(1))) scala> scala.quoted.run(v) val res1: Option[Int] = Some(2) diff --git a/docs/docs/reference/metaprogramming/staging.md b/docs/docs/reference/metaprogramming/staging.md index 7e9355cc2673..e6446d48f596 100644 --- a/docs/docs/reference/metaprogramming/staging.md +++ b/docs/docs/reference/metaprogramming/staging.md @@ -60,12 +60,15 @@ The framework as discussed so far allows code to be staged, i.e. be prepared to be executed at a later stage. To run that code, there is another method in class `Expr` called `run`. Note that `$` and `run` both map from `Expr[T]` to `T` but only `$` is subject to the PCP, whereas `run` is just a normal method. +Run provides a `QuoteContext` that can be used to show the expression in the scope of `run`. +On the other hand `withQuoteContext` provides a `QuoteContext` without evauating the expression. ```scala -sealed abstract class Expr[T] { - def run given (toolbox: Toolbox): T // run staged code - def show given (toolbox: Toolbox): String // show staged code -} +package scala.quoted + +def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = ... + +def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = ... ``` ## Example @@ -73,18 +76,21 @@ sealed abstract class Expr[T] { Now take exactly the same example as in [Macros](./macros.html). Assume that we do not want to pass an array statically but generated code at run-time and pass the value, also at run-time. Note, how we make a future-stage function of type -`Expr[Array[Int] => Int]` in line 4 below. Invoking the `.show` or `.run` we can -either show the code or run it respectivelly. +`Expr[Array[Int] => Int]` in line 4 below. Using `run { ... }` we can evaluate an +expression at runtime. Within the scope of `run` we can also invoke `show` on an expression +to get a source-like representation of the expression. ```scala // make available the necessary toolbox for runtime code generation implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) -val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => ${sum('arr)}} - -println(stagedSum.show) +val f: Array[Int] => Int = run { + val stagedSum: Expr[Array[Int] => Int] = '{ (arr: Array[Int]) => ${sum('arr)}} + println(stagedSum.show) // Prints "(arr: Array[Int]) => { var sum = 0; ... }" + stagedSum +} -stagedSum.run.apply(Array(1, 2, 3)) // Returns 6 +f.apply(Array(1, 2, 3)) // Returns 6 ``` Note that if we need to run the main (in an object called `Test`) after diff --git a/library/src-3.x/scala/internal/Quoted.scala b/library/src-3.x/scala/internal/Quoted.scala index 25af38de4c9a..b006a10ff1f5 100644 --- a/library/src-3.x/scala/internal/Quoted.scala +++ b/library/src-3.x/scala/internal/Quoted.scala @@ -25,4 +25,6 @@ object Quoted { @compileTimeOnly("Illegal reference to `scala.internal.Quoted.patternBindHole`") class patternBindHole extends Annotation + /** Artifact of type splicing */ + class quoteTypeTag extends Annotation } diff --git a/library/src-3.x/scala/quoted/Expr.scala b/library/src-3.x/scala/quoted/Expr.scala index c9d0271ed6cb..f4b158ff76f0 100644 --- a/library/src-3.x/scala/quoted/Expr.scala +++ b/library/src-3.x/scala/quoted/Expr.scala @@ -2,6 +2,8 @@ package scala package quoted { + import scala.quoted.show.SyntaxHighlight + sealed abstract class Expr[+T] { /** Evaluate the contents of this expression and return the result. @@ -9,7 +11,7 @@ package quoted { * May throw a FreeVariableError on expressions that came from a macro. */ @deprecated("Use scala.quoted.run", "") - final def run(implicit toolbox: Toolbox): T = toolbox.run(this) + final def run(implicit toolbox: Toolbox): T = toolbox.run(_ => this) } @@ -18,8 +20,13 @@ package quoted { import scala.internal.quoted._ implicit class ExprOps[T](expr: Expr[T]) { + + /** Show a source code like representation of this expression without syntax highlight */ + def show(implicit qctx: QuoteContext): String = qctx.show(expr, SyntaxHighlight.plain) + /** Show a source code like representation of this expression */ - def show(implicit toolbox: Toolbox): String = toolbox.show(expr) + def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(expr, syntaxHighlight) + } /** Converts a tuple `(T1, ..., Tn)` to `(Expr[T1], ..., Expr[Tn])` */ diff --git a/library/src-3.x/scala/quoted/Type.scala b/library/src-3.x/scala/quoted/Type.scala index d217445d4980..d8100ef7580d 100644 --- a/library/src-3.x/scala/quoted/Type.scala +++ b/library/src-3.x/scala/quoted/Type.scala @@ -2,6 +2,7 @@ package scala package quoted { import scala.internal.quoted.TaggedType + import scala.quoted.show.SyntaxHighlight sealed abstract class Type[T <: AnyKind] { type `$splice` = T @@ -10,9 +11,14 @@ package quoted { /** Some basic type tags, currently incomplete */ object Type { - implicit object TypeOps { + implicit class TypeOps[T](tpe: Type[T]) { + + /** Show a source code like representation of this type without syntax highlight */ + def show(implicit qctx: QuoteContext): String = qctx.show(tpe, SyntaxHighlight.plain) + /** Show a source code like representation of this type */ - def (tpe: Type[T]) show[T] given Toolbox: String = the[Toolbox].show(tpe.asInstanceOf[Type[Any]]) + def show(syntaxHighlight: SyntaxHighlight)(implicit qctx: QuoteContext): String = qctx.show(tpe, syntaxHighlight) + } implicit val UnitTag: Type[Unit] = new TaggedType[Unit] diff --git a/library/src-3.x/scala/quoted/package.scala b/library/src-3.x/scala/quoted/package.scala index abfc93786018..b90ebb1cf090 100644 --- a/library/src-3.x/scala/quoted/package.scala +++ b/library/src-3.x/scala/quoted/package.scala @@ -3,18 +3,49 @@ package scala package object quoted { /** Evaluate the contents of this expression and return the result. + * It provides a new QuoteContext that is only valid within the scope the argument. * * Usage: * ``` - * val e: T = run { - * expr + * val e: T = run { // (given qctx: QuoteContext) => + * expr * } * ``` * where `expr: Expr[T]` - * + * + * This method should not be called in a context where there is already has a `QuoteContext` + * such as within a `run` or a `withQuoteContext`. + * * May throw a FreeVariableError on expressions that came from a macro. */ - def run[T](expr: Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr) + def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = toolbox.run(expr given _) + + /** Provide a new quote context within the scope of the argument that is only valid within the scope the argument. + * Return the result of the argument. + * + * Usage: + * ``` + * val e: T = withQuoteContext { // (given qctx: QuoteContext) => + * thunk + * } + * ``` + * where `thunk: T` + * + * This method should not be called in a context where there is already has a `QuoteContext` + * such as within a `run` or a `withQuoteContext`. + */ + def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = { + var result: T = NoResult.asInstanceOf[T] + def dummyRun given QuoteContext: Expr[Unit] = { + result = thunk + '{} + } + toolbox.run(dummyRun given _) + assert(result != NoResult) // toolbox.run should have thrown an exception + result + } + + private object NoResult object autolift { implicit def autoToExpr[T: Liftable](x: T): Expr[T] = x.toExpr diff --git a/library/src-3.x/scala/tasty/reflect/QuotedOps.scala b/library/src-3.x/scala/tasty/reflect/QuotedOps.scala index 1e42d9070740..6ef2b8b5fc90 100644 --- a/library/src-3.x/scala/tasty/reflect/QuotedOps.scala +++ b/library/src-3.x/scala/tasty/reflect/QuotedOps.scala @@ -11,20 +11,12 @@ trait QuotedOps extends Core { self: Printers => /** Checked cast to a `quoted.Expr[U]` */ def cast[U: scala.quoted.Type](implicit ctx: Context): scala.quoted.Expr[U] = kernel.QuotedExpr_cast[U](expr) - - /** Show a source code like representation of this expression */ - def show(implicit ctx: Context): String = - unseal.show } implicit class QuotedTypeAPI[T <: AnyKind](tpe: scala.quoted.Type[T]) { /** View this expression `quoted.Type[T]` as a `TypeTree` */ def unseal(implicit ctx: Context): TypeTree = kernel.QuotedType_unseal(tpe) - - /** Show a source code like representation of this type */ - def show(implicit ctx: Context): String = - unseal.show } implicit class TermToQuotedAPI(term: Term) { diff --git a/library/src/scala/internal/Chars.scala b/library/src/scala/internal/Chars.scala new file mode 100644 index 000000000000..4c0ffeb24fa7 --- /dev/null +++ b/library/src/scala/internal/Chars.scala @@ -0,0 +1,96 @@ +package scala.internal + +import scala.annotation.switch +import java.lang.{Character => JCharacter} +import java.lang.Character.LETTER_NUMBER +import java.lang.Character.LOWERCASE_LETTER +import java.lang.Character.OTHER_LETTER +import java.lang.Character.TITLECASE_LETTER +import java.lang.Character.UPPERCASE_LETTER + +/** Contains constants and classifier methods for characters */ +object Chars { + + final val LF = '\u000A' + final val FF = '\u000C' + final val CR = '\u000D' + final val SU = '\u001A' + + /** Convert a character digit to an Int according to given base, + * -1 if no success + */ + def digit2int(ch: Char, base: Int): Int = { + val num = ( + if (ch <= '9') ch - '0' + else if ('a' <= ch && ch <= 'z') ch - 'a' + 10 + else if ('A' <= ch && ch <= 'Z') ch - 'A' + 10 + else -1 + ) + if (0 <= num && num < base) num else -1 + } + /** Buffer for creating '\ u XXXX' strings. */ + private[this] val char2uescapeArray = Array[Char]('\\', 'u', 0, 0, 0, 0) + + /** Convert a character to a backslash-u escape */ + def char2uescape(c: Char): String = { + @forceInline def hexChar(ch: Int): Char = + (( if (ch < 10) '0' else 'A' - 10 ) + ch).toChar + + char2uescapeArray(2) = hexChar((c >> 12) ) + char2uescapeArray(3) = hexChar((c >> 8) % 16) + char2uescapeArray(4) = hexChar((c >> 4) % 16) + char2uescapeArray(5) = hexChar((c ) % 16) + + new String(char2uescapeArray) + } + + /** Is character a line break? */ + def isLineBreakChar(c: Char): Boolean = (c: @switch) match { + case LF|FF|CR|SU => true + case _ => false + } + + /** Is character a whitespace character (but not a new line)? */ + def isWhitespace(c: Char): Boolean = + c == ' ' || c == '\t' || c == CR + + /** Can character form part of a doc comment variable $xxx? */ + def isVarPart(c: Char): Boolean = + '0' <= c && c <= '9' || 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' + + /** Can character start an alphanumeric Scala identifier? */ + def isIdentifierStart(c: Char): Boolean = + (c == '_') || (c == '$') || JCharacter.isUnicodeIdentifierStart(c) + + /** Can character form part of an alphanumeric Scala identifier? */ + def isIdentifierPart(c: Char): Boolean = + (c == '$') || JCharacter.isUnicodeIdentifierPart(c) + + /** Is character a math or other symbol in Unicode? */ + def isSpecial(c: Char): Boolean = { + val chtp = JCharacter.getType(c) + chtp == JCharacter.MATH_SYMBOL.toInt || chtp == JCharacter.OTHER_SYMBOL.toInt + } + + def isValidJVMChar(c: Char): Boolean = + !(c == '.' || c == ';' || c =='[' || c == '/') + + def isValidJVMMethodChar(c: Char): Boolean = + !(c == '.' || c == ';' || c =='[' || c == '/' || c == '<' || c == '>') + + private final val otherLetters = Set[Char]('\u0024', '\u005F') // '$' and '_' + private final val letterGroups = { + import JCharacter._ + Set[Byte](LOWERCASE_LETTER, UPPERCASE_LETTER, OTHER_LETTER, TITLECASE_LETTER, LETTER_NUMBER) + } + def isScalaLetter(ch: Char): Boolean = letterGroups(JCharacter.getType(ch).toByte) || otherLetters(ch) + + /** Can character form part of a Scala operator name? */ + def isOperatorPart(c : Char) : Boolean = (c: @switch) match { + case '~' | '!' | '@' | '#' | '%' | + '^' | '*' | '+' | '-' | '<' | + '>' | '?' | ':' | '=' | '&' | + '|' | '/' | '\\' => true + case c => isSpecial(c) + } +} diff --git a/library/src/scala/quoted/QuoteContext.scala b/library/src/scala/quoted/QuoteContext.scala new file mode 100644 index 000000000000..f3436f86ed47 --- /dev/null +++ b/library/src/scala/quoted/QuoteContext.scala @@ -0,0 +1,17 @@ +package scala.quoted + +import scala.quoted.show.SyntaxHighlight + +class QuoteContext(reflection: tasty.Reflection) { + + def show[T](expr: Expr[T], syntaxHighlight: SyntaxHighlight): String = { + import reflection._ + expr.unseal.show(syntaxHighlight) + } + + def show[T](tpe: Type[T], syntaxHighlight: SyntaxHighlight): String = { + import reflection._ + tpe.unseal.show(syntaxHighlight) + } + +} diff --git a/library/src/scala/quoted/Toolbox.scala b/library/src/scala/quoted/Toolbox.scala index ee834bdf236c..42fdb2d895fa 100644 --- a/library/src/scala/quoted/Toolbox.scala +++ b/library/src/scala/quoted/Toolbox.scala @@ -4,9 +4,7 @@ import scala.annotation.implicitNotFound @implicitNotFound("Could not find implicit quoted.Toolbox.\n\nDefault toolbox can be instantiated with:\n `implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)`\n\n") trait Toolbox { - def run[T](expr: Expr[T]): T - def show[T](expr: Expr[T]): String - def show[T](tpe: Type[T]): String + def run[T](expr: QuoteContext => Expr[T]): T } object Toolbox { @@ -38,7 +36,7 @@ object Toolbox { } /** Setting of the Toolbox instance. */ - case class Settings private (outDir: Option[String], showRawTree: Boolean, compilerArgs: List[String], color: Boolean) + case class Settings private (outDir: Option[String], showRawTree: Boolean, compilerArgs: List[String]) object Settings { @@ -46,17 +44,15 @@ object Toolbox { /** Make toolbox settings * @param outDir Output directory for the compiled quote. If set to None the output will be in memory - * @param color Print output with colors * @param showRawTree Do not remove quote tree artifacts * @param compilerArgs Compiler arguments. Use only if you know what you are doing. */ def make( // TODO avoid using default parameters (for binary compat) - color: Boolean = false, showRawTree: Boolean = false, outDir: Option[String] = None, compilerArgs: List[String] = Nil ): Settings = - new Settings(outDir, showRawTree, compilerArgs, color) + new Settings(outDir, showRawTree, compilerArgs) } class ToolboxNotFoundException(msg: String, cause: ClassNotFoundException) extends Exception(msg, cause) diff --git a/library/src/scala/quoted/show/SyntaxHighlight.scala b/library/src/scala/quoted/show/SyntaxHighlight.scala new file mode 100644 index 000000000000..84e4f33e46eb --- /dev/null +++ b/library/src/scala/quoted/show/SyntaxHighlight.scala @@ -0,0 +1,47 @@ +package scala.quoted.show + +trait SyntaxHighlight { + def highlightKeyword(str: String): String + def highlightTypeDef(str: String): String + def highlightLiteral(str: String): String + def highlightValDef(str: String): String + def highlightOperator(str: String): String + def highlightAnnotation(str: String): String + def highlightString(str: String): String + def highlightTripleQs: String +} + +object SyntaxHighlight { + + def ANSI: SyntaxHighlight = new SyntaxHighlight { + // Keep in sync with SyntaxHighlighting + private val NoColor = Console.RESET + private val CommentColor = Console.BLUE + private val KeywordColor = Console.YELLOW + private val ValDefColor = Console.CYAN + private val LiteralColor = Console.RED + private val StringColor = Console.GREEN + private val TypeColor = Console.MAGENTA + private val AnnotationColor = Console.MAGENTA + + def highlightKeyword(str: String): String = KeywordColor + str + NoColor + def highlightTypeDef(str: String): String = TypeColor + str + NoColor + def highlightLiteral(str: String): String = LiteralColor + str + NoColor + def highlightValDef(str: String): String = ValDefColor + str + NoColor + def highlightOperator(str: String): String = TypeColor + str + NoColor + def highlightAnnotation(str: String): String = AnnotationColor + str + NoColor + def highlightString(str: String): String = StringColor + str + NoColor + def highlightTripleQs: String = Console.RED_B + "???" + NoColor + } + + def plain: SyntaxHighlight = new SyntaxHighlight { + def highlightKeyword(str: String): String = str + def highlightTypeDef(str: String): String = str + def highlightLiteral(str: String): String = str + def highlightValDef(str: String): String = str + def highlightOperator(str: String): String = str + def highlightAnnotation(str: String): String = str + def highlightString(str: String): String = str + def highlightTripleQs: String = "???" + } +} diff --git a/library/src/scala/tasty/Reflection.scala b/library/src/scala/tasty/Reflection.scala index eafa6e3c12c2..503e61ebd7d6 100644 --- a/library/src/scala/tasty/Reflection.scala +++ b/library/src/scala/tasty/Reflection.scala @@ -41,6 +41,12 @@ class Reflection(val kernel: Kernel) val util: reflect.utils.TreeUtils { val reflect: self.type } = new reflect.utils.TreeUtils { val reflect: self.type = self } + + // TODO remove + // For backward compat with macros + implicit def reflectionToQuoteContext(implicit reflect: Reflection): scala.quoted.QuoteContext = + new scala.quoted.QuoteContext(reflect) + } object Reflection { diff --git a/library/src/scala/tasty/reflect/ContextOps.scala b/library/src/scala/tasty/reflect/ContextOps.scala index 470b071fd240..82a0230e14de 100644 --- a/library/src/scala/tasty/reflect/ContextOps.scala +++ b/library/src/scala/tasty/reflect/ContextOps.scala @@ -10,14 +10,6 @@ trait ContextOps extends Core { /** Returns the source file being compiled. The path is relative to the current working directory. */ def source: java.nio.file.Path = kernel.Context_source(self) - /** Returns true if the generated strings are allowed to use colors */ - def printColors: Boolean = kernel.Context_printColors(self) - - /** Returns a new context where printColors is true */ - def withColors: Context = kernel.Context_withColors(self) - - /** Returns a new context where printColors is false */ - def withoutColors: Context = kernel.Context_withoutColors(self) } /** Context of the macro expansion */ diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index 18e4ba66acb6..b36d4e0ff343 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -140,16 +140,6 @@ trait Kernel { /** Returns the source file being compiled. The path is relative to the current working directory. */ def Context_source(self: Context): java.nio.file.Path - /** Returns true if the generated strings are allowed to use colors */ - def Context_printColors(self: Context): Boolean - - /** Returns a new context where printColors is true */ - def Context_withColors(self: Context): Context - - /** Returns a new context where printColors is false */ - def Context_withoutColors(self: Context): Context - - // // REPORTING // diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index f27106fe0a43..75a473cf45c5 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -2,9 +2,7 @@ package scala.tasty package reflect import scala.annotation.switch - -import scala.tasty.util.SyntaxHighlightUtils._ -import scala.tasty.util.Chars +import scala.quoted.show.SyntaxHighlight trait Printers extends Core @@ -24,60 +22,81 @@ trait Printers implicit class TreeShowDeco(tree: Tree) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showTree(tree) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showTree(tree) + + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showTree(tree) } /** Adds `show` as an extension method of a `TypeOrBounds` */ implicit class TypeOrBoundsShowDeco(tpe: TypeOrBounds) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showTypeOrBounds(tpe) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showTypeOrBounds(tpe) + + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showTypeOrBounds(tpe) } /** Adds `show` as an extension method of a `Pattern` */ implicit class PatternShowDeco(pattern: Pattern) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showPattern(pattern) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showPattern(pattern) + + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showPattern(pattern) } /** Adds `show` as an extension method of a `Constant` */ implicit class ConstantShowDeco(const: Constant) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showConstant(const) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showConstant(const) + + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showConstant(const) } /** Adds `show` as an extension method of a `Symbol` */ implicit class SymbolShowDeco(symbol: Symbol) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showSymbol(symbol) + /** Shows the tree as fully typed source code */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showSymbol(symbol) + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showSymbol(symbol) } /** Adds `show` as an extension method of a `Flags` */ implicit class FlagsShowDeco(flags: Flags) { /** Shows the tree as extractors */ def showExtractors(implicit ctx: Context): String = new ExtractorsPrinter().showFlags(flags) - /** Shows the tree as fully typed source code. - * Will print Ansi colors if ctx.printColors is enabled. - */ - def show(implicit ctx: Context): String = new SourceCodePrinter().showFlags(flags) + + /** Shows the tree as fully typed source code */ + def show(implicit ctx: Context): String = show(SyntaxHighlight.plain) + + /** Shows the tree as fully typed source code */ + def show(syntaxHighlight: SyntaxHighlight)(implicit ctx: Context): String = + new SourceCodePrinter(syntaxHighlight).showFlags(flags) } + abstract class Printer { def showTree(tree: Tree)(implicit ctx: Context): String @@ -435,9 +454,8 @@ trait Printers } - class SourceCodePrinter extends Printer { - - private def color(implicit ctx: Context): Boolean = kernel.Context_printColors(ctx) + class SourceCodePrinter(syntaxHighlight: SyntaxHighlight) extends Printer { + import syntaxHighlight._ def showTree(tree: Tree)(implicit ctx: Context): String = (new Buffer).printTree(tree).result() @@ -563,18 +581,18 @@ trait Printers printDefAnnotations(cdef) val flags = cdef.symbol.flags - if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ", color) - if (flags.is(Flags.Sealed)) this += highlightKeyword("sealed ", color) - if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ", color) - if (flags.is(Flags.Case)) this += highlightKeyword("case ", color) + if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ") + if (flags.is(Flags.Sealed)) this += highlightKeyword("sealed ") + if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ") + if (flags.is(Flags.Case)) this += highlightKeyword("case ") if (name == "package$") { - this += highlightKeyword("package object ", color) += highlightTypeDef(cdef.symbol.owner.name.stripSuffix("$"), color) + this += highlightKeyword("package object ") += highlightTypeDef(cdef.symbol.owner.name.stripSuffix("$")) } - else if (flags.is(Flags.Object)) this += highlightKeyword("object ", color) += highlightTypeDef(name.stripSuffix("$"), color) - else if (flags.is(Flags.Trait)) this += highlightKeyword("trait ", color) += highlightTypeDef(name, color) - else if (flags.is(Flags.Abstract)) this += highlightKeyword("abstract class ", color) += highlightTypeDef(name, color) - else this += highlightKeyword("class ", color) += highlightTypeDef(name, color) + else if (flags.is(Flags.Object)) this += highlightKeyword("object ") += highlightTypeDef(name.stripSuffix("$")) + else if (flags.is(Flags.Trait)) this += highlightKeyword("trait ") += highlightTypeDef(name) + else if (flags.is(Flags.Abstract)) this += highlightKeyword("abstract class ") += highlightTypeDef(name) + else this += highlightKeyword("class ") += highlightTypeDef(name) val typeParams = stats.collect { case IsTypeDef(targ) => targ }.filter(_.symbol.isTypeParam).zip(targs) if (!flags.is(Flags.Object)) { @@ -591,7 +609,7 @@ trait Printers case _ => true } if (parents1.nonEmpty) - this += highlightKeyword(" extends ", color) + this += highlightKeyword(" extends ") def printParent(parent: Tree /* Term | TypeTree */, needEmptyParens: Boolean = false): Unit = parent match { case IsTypeTree(parent) => @@ -617,13 +635,13 @@ trait Printers case x :: Nil => printParent(x) case x :: xs => printParent(x) - this += highlightKeyword(" with ", color) + this += highlightKeyword(" with ") printSeparated(xs) } printSeparated(parents1) if (derived.nonEmpty) { - this += highlightKeyword(" derives ", color) + this += highlightKeyword(" derives ") printTypeTrees(derived, ", ") } @@ -658,7 +676,7 @@ trait Printers val Some(ValDef(name, tpt, _)) = self indented { val name1 = if (name == "_") "this" else name - this += " " += highlightValDef(name1, color) += ": " + this += " " += highlightValDef(name1) += ": " printTypeTree(tpt)(Some(cdef.symbol)) this += " =>" } @@ -682,24 +700,24 @@ trait Printers case IsTypeDef(tdef @ TypeDef(name, rhs)) => printDefAnnotations(tdef) - this += highlightKeyword("type ", color) + this += highlightKeyword("type ") printTargDef((tdef, tdef), isMember = true) case IsValDef(vdef @ ValDef(name, tpt, rhs)) => printDefAnnotations(vdef) val flags = vdef.symbol.flags - if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ", color) - if (flags.is(Flags.Override)) this += highlightKeyword("override ", color) - if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ", color) + if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ") + if (flags.is(Flags.Override)) this += highlightKeyword("override ") + if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ") printProtectedOrPrivate(vdef) - if (flags.is(Flags.Lazy)) this += highlightKeyword("lazy ", color) - if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightKeyword("var ", color) - else this += highlightKeyword("val ", color) + if (flags.is(Flags.Lazy)) this += highlightKeyword("lazy ") + if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightKeyword("var ") + else this += highlightKeyword("val ") - this += highlightValDef(name, color) += ": " + this += highlightValDef(name) += ": " printTypeTree(tpt) rhs match { case Some(tree) => @@ -712,11 +730,11 @@ trait Printers case While(cond, body) => (cond, body) match { case (Block(Block(Nil, body1) :: Nil, Block(Nil, cond1)), Literal(Constant.Unit())) => - this += highlightKeyword("do ", color) - printTree(body1) += highlightKeyword(" while ", color) + this += highlightKeyword("do ") + printTree(body1) += highlightKeyword(" while ") inParens(printTree(cond1)) case _ => - this += highlightKeyword("while ", color) + this += highlightKeyword("while ") inParens(printTree(cond)) += " " printTree(body) } @@ -738,14 +756,14 @@ trait Printers val isConstructor = name == "" val flags = ddef.symbol.flags - if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ", color) - if (flags.is(Flags.Inline)) this += highlightKeyword("inline ", color) - if (flags.is(Flags.Override)) this += highlightKeyword("override ", color) - if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ", color) + if (flags.is(Flags.Implicit)) this += highlightKeyword("implicit ") + if (flags.is(Flags.Inline)) this += highlightKeyword("inline ") + if (flags.is(Flags.Override)) this += highlightKeyword("override ") + if (flags.is(Flags.Final) && !flags.is(Flags.Object)) this += highlightKeyword("final ") printProtectedOrPrivate(ddef) - this += highlightKeyword("def ", color) += highlightValDef((if (isConstructor) "this" else name), color) + this += highlightKeyword("def ") += highlightValDef((if (isConstructor) "this" else name)) printTargsDefs(targs.zip(targs)) val it = argss.iterator while (it.hasNext) @@ -857,12 +875,12 @@ trait Printers printTree(term) case _ => printTree(term) - this += ": " += highlightTypeDef("_*", color) + this += ": " += highlightTypeDef("_*") } case _ => inParens { printTree(term) - this += (if (Chars.isOperatorPart(sb.last)) " : " else ": ") + this += (if (scala.internal.Chars.isOperatorPart(sb.last)) " : " else ": ") def printTypeOrAnnots(tpe: Type): Unit = tpe match { case Type.AnnotatedType(tp, annot) if tp == term.tpe => printAnnotation(annot) @@ -897,32 +915,32 @@ trait Printers this case If(cond, thenp, elsep) => - this += highlightKeyword("if ", color) + this += highlightKeyword("if ") inParens(printTree(cond)) this += " " printTree(thenp) - this+= highlightKeyword(" else ", color) + this+= highlightKeyword(" else ") printTree(elsep) case Match(selector, cases) => printQualTree(selector) - this += highlightKeyword(" match", color) + this += highlightKeyword(" match") inBlock(printCases(cases, lineBreak())) case ImpliedMatch(cases) => - this += highlightKeyword("delegate match", color) + this += highlightKeyword("delegate match") inBlock(printCases(cases, lineBreak())) case Try(body, cases, finallyOpt) => - this += highlightKeyword("try ", color) + this += highlightKeyword("try ") printTree(body) if (cases.nonEmpty) { - this += highlightKeyword(" catch", color) + this += highlightKeyword(" catch") inBlock(printCases(cases, lineBreak())) } finallyOpt match { case Some(t) => - this += highlightKeyword(" finally ", color) + this += highlightKeyword(" finally ") printTree(t) case None => this @@ -999,7 +1017,11 @@ trait Printers def printFlatBlock(stats: List[Statement], expr: Term)(implicit elideThis: Option[Symbol]): Buffer = { val (stats1, expr1) = flatBlock(stats, expr) // Remove Lambda nodes, lambdas are printed by their definition - val stats2 = stats1.filter { case Lambda(_, _) => false; case _ => true } + val stats2 = stats1.filter { + case Lambda(_, _) => false + case IsTypeDef(tree) => !tree.symbol.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag") + case _ => true + } val (stats3, expr3) = expr1 match { case Lambda(_, _) => val init :+ last = stats2 @@ -1169,9 +1191,9 @@ trait Printers if (isDef) { if (argDef.symbol.flags.is(Flags.Covariant)) { - this += highlightValDef("+", color) + this += highlightValDef("+") } else if (argDef.symbol.flags.is(Flags.Contravariant)) { - this += highlightValDef("-", color) + this += highlightValDef("-") } } @@ -1267,19 +1289,19 @@ trait Printers printedPrefix = true } printedPrefix |= printProtectedOrPrivate(vdef) - if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightValDef("var ", color) - else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAcessor)) this += highlightValDef("val ", color) + if (vdef.symbol.flags.is(Flags.Mutable)) this += highlightValDef("var ") + else if (printedPrefix || !vdef.symbol.flags.is(Flags.CaseAcessor)) this += highlightValDef("val ") } } case _ => } - this += highlightValDef(name, color) += ": " + this += highlightValDef(name) += ": " printTypeTree(arg.tpt) } def printCaseDef(caseDef: CaseDef): Buffer = { - this += highlightValDef("case ", color) + this += highlightValDef("case ") printPattern(caseDef.pattern) caseDef.guard match { case Some(t) => @@ -1287,7 +1309,7 @@ trait Printers printTree(t) case None => } - this += highlightValDef(" =>", color) + this += highlightValDef(" =>") indented { caseDef.rhs match { case Block(stats, expr) => @@ -1301,9 +1323,9 @@ trait Printers } def printTypeCaseDef(caseDef: TypeCaseDef): Buffer = { - this += highlightValDef("case ", color) + this += highlightValDef("case ") printTypeTree(caseDef.pattern) - this += highlightValDef(" => ", color) + this += highlightValDef(" => ") printTypeTree(caseDef.rhs) this } @@ -1319,7 +1341,7 @@ trait Printers this += name case Pattern.Bind(name, Pattern.TypeTest(tpt)) => - this += highlightValDef(name, color) += ": " + this += highlightValDef(name) += ": " printTypeTree(tpt) case Pattern.Bind(name, pattern) => @@ -1354,22 +1376,22 @@ trait Printers } def printConstant(const: Constant): Buffer = const match { - case Constant.Unit() => this += highlightLiteral("()", color) - case Constant.Null() => this += highlightLiteral("null", color) - case Constant.Boolean(v) => this += highlightLiteral(v.toString, color) - case Constant.Byte(v) => this += highlightLiteral(v.toString, color) - case Constant.Short(v) => this += highlightLiteral(v.toString, color) - case Constant.Int(v) => this += highlightLiteral(v.toString, color) - case Constant.Long(v) => this += highlightLiteral(v.toString + "L", color) - case Constant.Float(v) => this += highlightLiteral(v.toString + "f", color) - case Constant.Double(v) => this += highlightLiteral(v.toString, color) - case Constant.Char(v) => this += highlightString('\'' + escapedChar(v) + '\'', color) - case Constant.String(v) => this += highlightString('"' + escapedString(v) + '"', color) + case Constant.Unit() => this += highlightLiteral("()") + case Constant.Null() => this += highlightLiteral("null") + case Constant.Boolean(v) => this += highlightLiteral(v.toString) + case Constant.Byte(v) => this += highlightLiteral(v.toString) + case Constant.Short(v) => this += highlightLiteral(v.toString) + case Constant.Int(v) => this += highlightLiteral(v.toString) + case Constant.Long(v) => this += highlightLiteral(v.toString + "L") + case Constant.Float(v) => this += highlightLiteral(v.toString + "f") + case Constant.Double(v) => this += highlightLiteral(v.toString) + case Constant.Char(v) => this += highlightString('\'' + escapedChar(v) + '\'') + case Constant.String(v) => this += highlightString('"' + escapedString(v) + '"') case Constant.ClassTag(v) => this += "classOf" inSquare(printType(v)) case Constant.Symbol(v) => - this += highlightLiteral("'" + v.name, color) + this += highlightLiteral("'" + v.name) } def printTypeOrBoundsTree(tpt: Tree)(implicit elideThis: Option[Symbol] = None): Buffer = tpt match { @@ -1417,10 +1439,10 @@ trait Printers printType(tree.tpe) case TypeSelect(qual, name) => - printTree(qual) += "." += highlightTypeDef(name, color) + printTree(qual) += "." += highlightTypeDef(name) case Projection(qual, name) => - printTypeTree(qual) += "#" += highlightTypeDef(name, color) + printTypeTree(qual) += "#" += highlightTypeDef(name) case Singleton(ref) => printTree(ref) @@ -1443,7 +1465,7 @@ trait Printers case Types.RepeatedAnnotation() => val Types.Sequence(tp) = tpt.tpe printType(tp) - this += highlightTypeDef("*", color) + this += highlightTypeDef("*") case _ => printTypeTree(tpt) this += " " @@ -1452,26 +1474,23 @@ trait Printers case MatchTypeTree(bound, selector, cases) => printTypeTree(selector) - this += highlightKeyword(" match ", color) + this += highlightKeyword(" match ") inBlock(printTypeCases(cases, lineBreak())) case ByName(result) => - this += highlightTypeDef("=> ", color) + this += highlightTypeDef("=> ") printTypeTree(result) case LambdaTypeTree(tparams, body) => printTargsDefs(tparams.zip(tparams), isDef = false) - this += highlightTypeDef(" => ", color) + this += highlightTypeDef(" => ") printTypeOrBoundsTree(body) case TypeBind(name, _) => - this += highlightTypeDef(name, color) + this += highlightTypeDef(name) - case TypeBlock(aliases, tpt) => - inBlock { - printTrees(aliases, lineBreak()) - printTypeTree(tpt) - } + case TypeBlock(_, tpt) => + printTypeTree(tpt) case _ => throw new MatchError(tree.showExtractors) @@ -1499,6 +1518,9 @@ trait Printers case Type.ConstantType(const) => printConstant(const) + case Type.SymRef(sym, _) if sym.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag") => + printType(tpe.dealias) + case Type.SymRef(sym, prefix) if sym.isType => prefix match { case Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) => @@ -1518,30 +1540,30 @@ trait Printers printType(prefix) this += "." } - this += highlightTypeDef(sym.name.stripSuffix("$"), color) + this += highlightTypeDef(sym.name.stripSuffix("$")) case Type.SymRef(sym, prefix) if sym.isTerm => prefix match { case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) => - this += highlightTypeDef(sym.name, color) + this += highlightTypeDef(sym.name) case _ => printTypeOrBound(prefix) if (sym.name != "package") - this += "." += highlightTypeDef(sym.name, color) + this += "." += highlightTypeDef(sym.name) this } case Type.TermRef(name, prefix) => prefix match { case Type.ThisType(Types.EmptyPackage()) => - this += highlightTypeDef(name, color) + this += highlightTypeDef(name) case IsType(prefix) => printType(prefix) if (name != "package") - this += "." += highlightTypeDef(name, color) + this += "." += highlightTypeDef(name) this case NoPrefix() => - this += highlightTypeDef(name, color) + this += highlightTypeDef(name) } case Type.TypeRef(name, prefix) => @@ -1549,14 +1571,16 @@ trait Printers case NoPrefix() | Type.ThisType(Types.EmptyPackage()) => case IsType(prefix) => printType(prefix) += "." } - if (name.endsWith("$")) this += highlightTypeDef(name.stripSuffix("$"), color) += ".type" - else this += highlightTypeDef(name, color) + if (name.endsWith("$")) this += highlightTypeDef(name.stripSuffix("$")) += ".type" + else this += highlightTypeDef(name) case tpe @ Type.Refinement(_, _, _) => printRefinement(tpe) case Type.AppliedType(tp, args) => - tp match { + normalize(tp) match { + case Type.IsTypeLambda(tp) => + printType(tpe.dealias) case Type.TypeRef("", Types.ScalaPackage()) => this += "_*" case _ => @@ -1572,28 +1596,28 @@ trait Printers case Type.AndType(left, right) => printType(left) - this += highlightTypeDef(" & ", color) + this += highlightTypeDef(" & ") printType(right) case Type.OrType(left, right) => printType(left) - this += highlightTypeDef(" | ", color) + this += highlightTypeDef(" | ") printType(right) case Type.MatchType(bound, scrutinee, cases) => printType(scrutinee) - this += highlightKeyword(" match ", color) + this += highlightKeyword(" match ") inBlock(printTypes(cases, lineBreak())) case Type.ByNameType(tp) => - this += highlightTypeDef(" => ", color) + this += highlightTypeDef(" => ") printType(tp) case Type.ThisType(tp) => tp match { case Type.SymRef(cdef, _) if !cdef.flags.is(Flags.Object) => printFullClassName(tp) - this += highlightTypeDef(".this", color) + this += highlightTypeDef(".this") case Type.TypeRef(name, prefix) if name.endsWith("$") => prefix match { case NoPrefix() | Type.ThisType(Types.EmptyPackage() | Types.RootPackage()) => @@ -1601,18 +1625,18 @@ trait Printers printTypeOrBound(prefix) this += "." } - this += highlightTypeDef(name.stripSuffix("$"), color) + this += highlightTypeDef(name.stripSuffix("$")) case _ => printType(tp) } case Type.SuperType(thistpe, supertpe) => printType(supertpe) - this += highlightTypeDef(".super", color) + this += highlightTypeDef(".super") case Type.TypeLambda(paramNames, tparams, body) => inSquare(printMethodicTypeParams(paramNames, tparams)) - this += highlightTypeDef(" => ", color) + this += highlightTypeDef(" => ") printTypeOrBound(body) case Type.ParamRef(lambda, idx) => @@ -1626,7 +1650,7 @@ trait Printers printType(tpe) case Type.RecursiveThis(_) => - this += highlightTypeDef("this", color) + this += highlightTypeDef("this") case Type.IsMethodType(tpe) => this += "(" @@ -1653,6 +1677,13 @@ trait Printers throw new MatchError(tpe.showExtractors) } + private def normalize(tpe: TypeOrBounds): TypeOrBounds = tpe match { + case Type.IsSymRef(tpe) + if tpe.typeSymbol.annots.exists(_.symbol.owner.fullName == "scala.internal.Quoted$.quoteTypeTag") => + tpe.dealias + case _ => tpe + } + def printImportSelector(sel: ImportSelector): Buffer = sel match { case SimpleSelector(Id(name)) => this += name case OmitSelector(Id(name)) => this += name += " => _" @@ -1660,11 +1691,11 @@ trait Printers } def printDefinitionName(sym: Definition): Buffer = sym match { - case ValDef(name, _, _) => this += highlightValDef(name, color) - case DefDef(name, _, _, _, _) => this += highlightValDef(name, color) - case ClassDef(name, _, _, _, _, _) => this += highlightTypeDef(name.stripSuffix("$"), color) - case TypeDef(name, _) => this += highlightTypeDef(name, color) - case PackageDef(name, _) => this += highlightTypeDef(name, color) + case ValDef(name, _, _) => this += highlightValDef(name) + case DefDef(name, _, _, _, _) => this += highlightValDef(name) + case ClassDef(name, _, _, _, _, _) => this += highlightTypeDef(name.stripSuffix("$")) + case TypeDef(name, _) => this += highlightTypeDef(name) + case PackageDef(name, _) => this += highlightTypeDef(name) } def printAnnotation(annot: Term)(implicit elideThis: Option[Symbol]): Buffer = { @@ -1714,13 +1745,13 @@ trait Printers this += lineBreak() info match { case IsTypeBounds(info) => - this += highlightKeyword("type ", color) += highlightTypeDef(name, color) + this += highlightKeyword("type ") += highlightTypeDef(name) printBounds(info) case Type.ByNameType(_) | Type.MethodType(_, _, _) | Type.TypeLambda(_, _, _) => - this += highlightKeyword("def ", color) += highlightTypeDef(name, color) + this += highlightKeyword("def ") += highlightTypeDef(name) printMethodicType(info) case IsType(info) => - this += highlightKeyword("val ", color) += highlightValDef(name, color) + this += highlightKeyword("val ") += highlightValDef(name) printMethodicType(info) } } @@ -1783,7 +1814,7 @@ trait Printers case _ => printFullClassName(within) } if (definition.symbol.flags.is(Flags.Protected)) { - this += highlightKeyword("protected", color) + this += highlightKeyword("protected") definition.symbol.protectedWithin match { case Some(within) => inSquare(printWithin(within)) @@ -1793,7 +1824,7 @@ trait Printers } else { definition.symbol.privateWithin match { case Some(within) => - this += highlightKeyword("private", color) + this += highlightKeyword("private") inSquare(printWithin(within)) prefixWasPrinted = true case _ => diff --git a/library/src/scala/tasty/util/Chars.scala b/library/src/scala/tasty/util/Chars.scala index 433b94e868a7..795eddea4b1a 100644 --- a/library/src/scala/tasty/util/Chars.scala +++ b/library/src/scala/tasty/util/Chars.scala @@ -9,6 +9,7 @@ import java.lang.Character.TITLECASE_LETTER import java.lang.Character.UPPERCASE_LETTER /** Contains constants and classifier methods for characters */ +@deprecated("Use scala.internal.Chars", "0.17") object Chars { final val LF = '\u000A' diff --git a/library/src/scala/tasty/util/SyntaxHighlightUtils.scala b/library/src/scala/tasty/util/SyntaxHighlightUtils.scala deleted file mode 100644 index d19c700a3e90..000000000000 --- a/library/src/scala/tasty/util/SyntaxHighlightUtils.scala +++ /dev/null @@ -1,25 +0,0 @@ -package scala.tasty -package util - -object SyntaxHighlightUtils { - - // Keep in sync with SyntaxHighlighting - private val NoColor = Console.RESET - private val CommentColor = Console.BLUE - private val KeywordColor = Console.YELLOW - private val ValDefColor = Console.CYAN - private val LiteralColor = Console.RED - private val StringColor = Console.GREEN - private val TypeColor = Console.MAGENTA - private val AnnotationColor = Console.MAGENTA - - def highlightKeyword(str: String, withColor: Boolean) = if (withColor) { KeywordColor + str + NoColor } else str - def highlightTypeDef(str: String, withColor: Boolean) = if (withColor) { TypeColor + str + NoColor } else str - def highlightLiteral(str: String, withColor: Boolean) = if (withColor) { LiteralColor + str + NoColor } else str - def highlightValDef(str: String, withColor: Boolean) = if (withColor) { ValDefColor + str + NoColor } else str - def highlightOperator(str: String, withColor: Boolean) = if (withColor) { TypeColor + str + NoColor } else str - def highlightAnnotation(str: String, withColor: Boolean) = if (withColor) { AnnotationColor + str + NoColor } else str - def highlightString(str: String, withColor: Boolean) = if (withColor) { StringColor + str + NoColor } else str - val tripleQs = Console.RED_B + "???" + NoColor - -} \ No newline at end of file diff --git a/tests/neg-with-compiler/quote-run-in-macro-1/quoted_1.scala b/tests/neg-with-compiler/quote-run-in-macro-1/quoted_1.scala index 27590f387487..b734f4998388 100644 --- a/tests/neg-with-compiler/quote-run-in-macro-1/quoted_1.scala +++ b/tests/neg-with-compiler/quote-run-in-macro-1/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) inline def foo(i: => Int): Int = ${ fooImpl('i) } def fooImpl(i: Expr[Int]): Expr[Int] = { - val y: Int = i.run + val y: Int = run(i) y } } diff --git a/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala b/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala index 1f1f38ec20a1..e2aa77480563 100644 --- a/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala +++ b/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { inline def foo(i: => Int): Int = ${ fooImpl('i) } def fooImpl(i: Expr[Int]): Expr[Int] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val y: Int = i.run + val y: Int = run(i) y } } diff --git a/tests/run-with-compiler/i3823-b.scala b/tests/run-with-compiler/i3823-b.scala index 958ef94e1b56..a1048e4937d8 100644 --- a/tests/run-with-compiler/i3823-b.scala +++ b/tests/run-with-compiler/i3823-b.scala @@ -1,10 +1,10 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { def f[T](x: Expr[T])(implicit t: Type[T]) = '{ val z: $t = $x } - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) println(f('{2})(Type.IntTag).show) } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/i3823-c.scala b/tests/run-with-compiler/i3823-c.scala index 3efe37610519..61e393efab65 100644 --- a/tests/run-with-compiler/i3823-c.scala +++ b/tests/run-with-compiler/i3823-c.scala @@ -1,11 +1,10 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { def f[T](x: Expr[T])(implicit t: Type[T]) = '{ val z = $x } - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) println(f('{2})(Type.IntTag).show) } } - diff --git a/tests/run-with-compiler/i3823.scala b/tests/run-with-compiler/i3823.scala index 3e207e307d42..430b215acdf8 100644 --- a/tests/run-with-compiler/i3823.scala +++ b/tests/run-with-compiler/i3823.scala @@ -1,10 +1,10 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { def f[T: Type](x: Expr[T])(t: Type[T]) = '{ val z: $t = $x } - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) println(f('{2})('[Int]).show) } } \ No newline at end of file diff --git a/tests/run-with-compiler/i3847-b.scala b/tests/run-with-compiler/i3847-b.scala index 3c76fb547c15..a07c47ceefad 100644 --- a/tests/run-with-compiler/i3847-b.scala +++ b/tests/run-with-compiler/i3847-b.scala @@ -13,8 +13,8 @@ object Arrays { } object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[List[Int]]] = Array[List[Int]](List(1, 2, 3)).toExpr diff --git a/tests/run-with-compiler/i3847.scala b/tests/run-with-compiler/i3847.scala index a8b071cc7bdb..4c05714d1767 100644 --- a/tests/run-with-compiler/i3847.scala +++ b/tests/run-with-compiler/i3847.scala @@ -13,11 +13,11 @@ object Arrays { } object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(this.getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(this.getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { import Arrays._ implicit val ct: Expr[ClassTag[Int]] = '{ClassTag.Int} val arr: Expr[Array[Int]] = Array[Int](1, 2, 3).toExpr println(arr.show) } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/i3876-b.scala b/tests/run-with-compiler/i3876-b.scala index ba854e80eee6..22eb62c3d3be 100644 --- a/tests/run-with-compiler/i3876-b.scala +++ b/tests/run-with-compiler/i3876-b.scala @@ -9,7 +9,8 @@ object Test { def f(x: Int): Int = x + x f } + println(run(f2(x))) - println(f2(x).show) + println(withQuoteContext(f2(x).show)) } } diff --git a/tests/run-with-compiler/i3876-c.scala b/tests/run-with-compiler/i3876-c.scala index aad2bfd063e8..7e9ab0baff5f 100644 --- a/tests/run-with-compiler/i3876-c.scala +++ b/tests/run-with-compiler/i3876-c.scala @@ -9,7 +9,8 @@ object Test { val f: (x: Int) => Int = x => x + x f } + println(run(f3(x))) - println(f3(x).show) // TODO improve printer + println(withQuoteContext(f3(x).show)) // TODO improve printer } } diff --git a/tests/run-with-compiler/i3876-d.scala b/tests/run-with-compiler/i3876-d.scala index a64dd09213bc..bcdbe8818abc 100644 --- a/tests/run-with-compiler/i3876-d.scala +++ b/tests/run-with-compiler/i3876-d.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(f4(x).show) + println(withQuoteContext(f4(x).show)) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876-e.scala b/tests/run-with-compiler/i3876-e.scala index a6cb5ab158d5..8b0b9e285612 100644 --- a/tests/run-with-compiler/i3876-e.scala +++ b/tests/run-with-compiler/i3876-e.scala @@ -9,7 +9,7 @@ object Test { inlineLambda } println(run(f4(x))) - println(f4(x).show) + println(withQuoteContext(f4(x).show)) } inline def inlineLambda <: Int => Int = x => x + x diff --git a/tests/run-with-compiler/i3876.scala b/tests/run-with-compiler/i3876.scala index 0b76e6c534c3..a1c57e438f14 100644 --- a/tests/run-with-compiler/i3876.scala +++ b/tests/run-with-compiler/i3876.scala @@ -6,7 +6,8 @@ object Test { val x: Expr[Int] = '{3} val f: Expr[Int => Int] = '{ (x: Int) => x + x } + println(run(f(x))) - println(f(x).show) + println(withQuoteContext(f(x).show)) } } diff --git a/tests/run-with-compiler/i3946.scala b/tests/run-with-compiler/i3946.scala index 73aece729e0b..eff2fa9a507b 100644 --- a/tests/run-with-compiler/i3946.scala +++ b/tests/run-with-compiler/i3946.scala @@ -3,7 +3,7 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val u: Expr[Unit] = '{} - println(u.show) + println(withQuoteContext(u.show)) println(run(u)) } } diff --git a/tests/run-with-compiler/i3947.scala b/tests/run-with-compiler/i3947.scala index d6fb9b9c81c1..4984b17deda6 100644 --- a/tests/run-with-compiler/i3947.scala +++ b/tests/run-with-compiler/i3947.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // classOf[Object] diff --git a/tests/run-with-compiler/i3947b.scala b/tests/run-with-compiler/i3947b.scala index f27cd8c04d64..93ea766e2f07 100644 --- a/tests/run-with-compiler/i3947b.scala +++ b/tests/run-with-compiler/i3947b.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitives diff --git a/tests/run-with-compiler/i3947b2.scala b/tests/run-with-compiler/i3947b2.scala index 5956b3da4df7..ecd892c81d58 100644 --- a/tests/run-with-compiler/i3947b2.scala +++ b/tests/run-with-compiler/i3947b2.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitives diff --git a/tests/run-with-compiler/i3947b3.scala b/tests/run-with-compiler/i3947b3.scala index cc5bfd616d48..5eccdc6334ce 100644 --- a/tests/run-with-compiler/i3947b3.scala +++ b/tests/run-with-compiler/i3947b3.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitives diff --git a/tests/run-with-compiler/i3947c.scala b/tests/run-with-compiler/i3947c.scala index ffd458237a05..851b8c9ebe94 100644 --- a/tests/run-with-compiler/i3947c.scala +++ b/tests/run-with-compiler/i3947c.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } test(classOf[Null]) diff --git a/tests/run-with-compiler/i3947d.scala b/tests/run-with-compiler/i3947d.scala index 78da0408257e..91140bfd28ba 100644 --- a/tests/run-with-compiler/i3947d.scala +++ b/tests/run-with-compiler/i3947d.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } test(classOf[Foo]) diff --git a/tests/run-with-compiler/i3947d2.scala b/tests/run-with-compiler/i3947d2.scala index 38852e71fbfd..dd923aaad160 100644 --- a/tests/run-with-compiler/i3947d2.scala +++ b/tests/run-with-compiler/i3947d2.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } test(classOf[foo.Foo]) diff --git a/tests/run-with-compiler/i3947e.scala b/tests/run-with-compiler/i3947e.scala index 39b6f54c2e3a..862a9a21a80e 100644 --- a/tests/run-with-compiler/i3947e.scala +++ b/tests/run-with-compiler/i3947e.scala @@ -6,12 +6,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // class Object diff --git a/tests/run-with-compiler/i3947f.scala b/tests/run-with-compiler/i3947f.scala index 68b4c562f01c..a6930736c103 100644 --- a/tests/run-with-compiler/i3947f.scala +++ b/tests/run-with-compiler/i3947f.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // class Array[Object] diff --git a/tests/run-with-compiler/i3947g.scala b/tests/run-with-compiler/i3947g.scala index 59343ddf9035..05b8c033df11 100644 --- a/tests/run-with-compiler/i3947g.scala +++ b/tests/run-with-compiler/i3947g.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitive arrays diff --git a/tests/run-with-compiler/i3947i.scala b/tests/run-with-compiler/i3947i.scala index 9739e27d207e..113b2d492e4d 100644 --- a/tests/run-with-compiler/i3947i.scala +++ b/tests/run-with-compiler/i3947i.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } // primitive arrays diff --git a/tests/run-with-compiler/i3947j.scala b/tests/run-with-compiler/i3947j.scala index c8f2b121f174..37788b716a3e 100644 --- a/tests/run-with-compiler/i3947j.scala +++ b/tests/run-with-compiler/i3947j.scala @@ -5,12 +5,12 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def test[T: Type](clazz: java.lang.Class[T]): Unit = { + def test[T: Type](clazz: java.lang.Class[T]): Unit = run { val lclazz = clazz.toExpr val name = '{ ($lclazz).getCanonicalName } println() println(name.show) - println(run(name)) + '{ println($name) } } test(classOf[Array[Array[Int]]]) diff --git a/tests/run-with-compiler/i4044a.scala b/tests/run-with-compiler/i4044a.scala index 30886ca3dfc7..9486c20bdc68 100644 --- a/tests/run-with-compiler/i4044a.scala +++ b/tests/run-with-compiler/i4044a.scala @@ -5,7 +5,7 @@ class Foo { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val e: Expr[Int] = '{3} val q = '{ ${ '{ $e } } } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044b.scala b/tests/run-with-compiler/i4044b.scala index b70f9882cee1..1c63e62f612d 100644 --- a/tests/run-with-compiler/i4044b.scala +++ b/tests/run-with-compiler/i4044b.scala @@ -22,6 +22,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = VarRef('{4})(varRef => '{ ${varRef.update('{3})}; ${varRef.expr} }) - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044c.scala b/tests/run-with-compiler/i4044c.scala index 558ec2d1b045..1777042fb563 100644 --- a/tests/run-with-compiler/i4044c.scala +++ b/tests/run-with-compiler/i4044c.scala @@ -4,7 +4,7 @@ class Foo { def foo: Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ ${ '{ ${ '{ 5 } } } } } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044d.scala b/tests/run-with-compiler/i4044d.scala index 512448e49f8d..583e9c4a2352 100644 --- a/tests/run-with-compiler/i4044d.scala +++ b/tests/run-with-compiler/i4044d.scala @@ -3,17 +3,20 @@ import scala.quoted._ class Foo { def foo: Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val a: Expr[Int] = '{3} - val q: Expr[Int] = '{ - val b = 3 - ${ - println("evaluating inner quote") - '{ - b + $a + run { + val a: Expr[Int] = '{3} + val q: Expr[Int] = '{ + val b = 3 + ${ + println("evaluating inner quote") + '{ + b + $a + } } } + println(q.show) + '{} } - println(q.show) } } diff --git a/tests/run-with-compiler/i4044e.scala b/tests/run-with-compiler/i4044e.scala index bef7315f5e81..49d5994812e7 100644 --- a/tests/run-with-compiler/i4044e.scala +++ b/tests/run-with-compiler/i4044e.scala @@ -7,7 +7,7 @@ class Foo { val f: Expr[Int] = '{5} val t: Type[Int] = '[Int] val q = '{ ${ '{ ($e + $f).asInstanceOf[$t] } } } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4044f.scala b/tests/run-with-compiler/i4044f.scala index bad5c8859a3b..0cedf8187110 100644 --- a/tests/run-with-compiler/i4044f.scala +++ b/tests/run-with-compiler/i4044f.scala @@ -14,7 +14,7 @@ class Foo { foo('{e1 + $u}, '{f1}) } } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/i4350.scala b/tests/run-with-compiler/i4350.scala index c1be9e8570dd..1f6da64ea0bb 100644 --- a/tests/run-with-compiler/i4350.scala +++ b/tests/run-with-compiler/i4350.scala @@ -1,13 +1,13 @@ -import scala.quoted.Type +import scala.quoted._ class Foo[T: Type] { def q = '{(null: Any).asInstanceOf[T]} } object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { println((new Foo[Object]).q.show) println((new Foo[String]).q.show) } diff --git a/tests/run-with-compiler/i5144.scala b/tests/run-with-compiler/i5144.scala index 6f124d2402f9..04906034b23f 100644 --- a/tests/run-with-compiler/i5144.scala +++ b/tests/run-with-compiler/i5144.scala @@ -8,7 +8,7 @@ object Test { def f(x: Int): Int = ${eval1('f)} } - def main(args: Array[String]): Unit = { + def main(args: Array[String]): Unit = withQuoteContext { val p = peval1() println(p.show) } diff --git a/tests/run-with-compiler/i5144b.scala b/tests/run-with-compiler/i5144b.scala index ebbc72e5780e..34ffb2a067f1 100644 --- a/tests/run-with-compiler/i5144b.scala +++ b/tests/run-with-compiler/i5144b.scala @@ -8,9 +8,10 @@ object Test { def f(x: Int): Int = ${eval1('f)} } - def main(args: Array[String]): Unit = { + def main(args: Array[String]): Unit = run { val p = peval1() println(p.show) + '{} } } \ No newline at end of file diff --git a/tests/run-with-compiler/i5152.scala b/tests/run-with-compiler/i5152.scala index be9532ed2c43..a4684bbcd787 100644 --- a/tests/run-with-compiler/i5152.scala +++ b/tests/run-with-compiler/i5152.scala @@ -8,9 +8,9 @@ object Test { lazy val f: Int => Int = ${eval1('{(y: Int) => f(y)})} } - def main(args: Array[String]): Unit = { + def main(args: Array[String]): Unit = withQuoteContext { val p = peval1() println(p.show) } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/i5161.check b/tests/run-with-compiler/i5161.check new file mode 100644 index 000000000000..27c72498d7f1 --- /dev/null +++ b/tests/run-with-compiler/i5161.check @@ -0,0 +1,7 @@ +run : Some(2) +show : scala.Tuple2.apply[scala.Option[scala.Int], scala.Option[scala.Int]](scala.Some.apply[scala.Int](1), scala.Some.apply[scala.Int](1)) match { + case scala.Tuple2(scala.Some(x), scala.Some(y)) => + scala.Some.apply[scala.Int](x.+(y)) + case _ => + scala.None +} diff --git a/tests/run-with-compiler/i5161.scala b/tests/run-with-compiler/i5161.scala new file mode 100644 index 000000000000..e1ea118ae76c --- /dev/null +++ b/tests/run-with-compiler/i5161.scala @@ -0,0 +1,31 @@ +import scala.quoted._ + +object Test { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + + enum Exp { + case Int2(x: Int) + case Add(e1: Exp, e2: Exp) + } + import Exp._ + + def evalTest(e: Exp): Expr[Option[Int]] = e match { + case Int2(x) => '{ Some(${x.toExpr}) } + case Add(e1, e2) => + '{ + (${evalTest(e1)}, ${evalTest(e2)}) match { + case (Some(x), Some(y)) => Some(x+y) + case _ => None + } + } + case null => '{ None } + } + + + def main(args: Array[String]): Unit = { + val test = Add(Int2(1), Int2(1)) + val res = evalTest(test) + println("run : " + run(res)) + println("show : " + withQuoteContext(res.show)) + } +} diff --git a/tests/run-with-compiler/i5161b.check b/tests/run-with-compiler/i5161b.check new file mode 100644 index 000000000000..a93920fde48e --- /dev/null +++ b/tests/run-with-compiler/i5161b.check @@ -0,0 +1,10 @@ +show0 : { + val x: scala.Option[scala.Int] = scala.Option.apply[scala.Int](3) + if (x.isInstanceOf[scala.Some[_ >: scala.Nothing <: scala.Any]]) scala.Option.apply[scala.Int](1) else scala.None +} +run1 : Some(1) +run2 : Some(1) +show3 : { + val x: scala.Option[scala.Int] = scala.Option.apply[scala.Int](3) + if (x.isInstanceOf[scala.Some[_ >: scala.Nothing <: scala.Any]]) scala.Option.apply[scala.Int](1) else scala.None +} diff --git a/tests/run-with-compiler/i5161b.scala b/tests/run-with-compiler/i5161b.scala new file mode 100644 index 000000000000..f52770930783 --- /dev/null +++ b/tests/run-with-compiler/i5161b.scala @@ -0,0 +1,17 @@ +import scala.quoted._ + +object Test { + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + + def main(args: Array[String]): Unit = { + val res = '{ + val x: Option[Int] = Option(3) + if (x.isInstanceOf[Some[_]]) Option(1) + else None + } + println("show0 : " + withQuoteContext(res.show)) + println("run1 : " + run(res)) + println("run2 : " + run(res)) + println("show3 : " + withQuoteContext(res.show)) + } +} diff --git a/tests/run-with-compiler/i5247.scala b/tests/run-with-compiler/i5247.scala index 1fb8793d6822..01b5393e23be 100644 --- a/tests/run-with-compiler/i5247.scala +++ b/tests/run-with-compiler/i5247.scala @@ -1,7 +1,7 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { println(foo[Object].show) println(bar[Object].show) } diff --git a/tests/run-with-compiler/i5965.check b/tests/run-with-compiler/i5965.check index f88ef8f53869..0f1c479d2902 100644 --- a/tests/run-with-compiler/i5965.check +++ b/tests/run-with-compiler/i5965.check @@ -1,17 +1,17 @@ { - val y: scala.collection.immutable.List[scala.Int] = scala.List.apply[scala.Int](1, 2, 3) + val y: [+A >: scala.Nothing <: scala.Any] => scala.collection.immutable.List[+A][scala.Int] = scala.List.apply[scala.Int](1, 2, 3) (y: scala.collection.immutable.List[scala.Int]) } List(1, 2, 3) { - val y: scala.Option[scala.Int] = scala.Option.apply[scala.Int](4) + val y: [+A >: scala.Nothing <: scala.Any] => scala.Option[+A][scala.Int] = scala.Option.apply[scala.Int](4) (y: scala.Option[scala.Int]) } Some(4) { - val y: scala.collection.immutable.Map[scala.Int, scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1)) + val y: [V >: scala.Nothing <: scala.Any] => scala.collection.immutable.Map[scala.Int, V][scala.Int] = scala.Predef.Map.apply[scala.Int, scala.Int](scala.Predef.ArrowAssoc[scala.Int](4).->[scala.Int](1)) (y: scala.collection.immutable.Map[scala.Int, scala.Int]) } diff --git a/tests/run-with-compiler/i5965.scala b/tests/run-with-compiler/i5965.scala index 58fa88f15e88..7b1a8cfa61a7 100644 --- a/tests/run-with-compiler/i5965.scala +++ b/tests/run-with-compiler/i5965.scala @@ -8,15 +8,15 @@ object Test { def main(args: Array[String]): Unit = { '[List] val list = bound('{List(1, 2, 3)}) - println(list.show) + println(withQuoteContext(list.show)) println(run(list)) val opt = bound('{Option(4)}) - println(opt.show) + println(withQuoteContext(opt.show)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(map.show) + println(withQuoteContext(map.show)) println(run(map)) } diff --git a/tests/run-with-compiler/i5965b.scala b/tests/run-with-compiler/i5965b.scala index fc1fc9eb0a59..e806cd847957 100644 --- a/tests/run-with-compiler/i5965b.scala +++ b/tests/run-with-compiler/i5965b.scala @@ -9,15 +9,15 @@ object Test { '[List] val list = bound('{List(1, 2, 3)}) - println(list.show) + println(withQuoteContext(list.show)) println(run(list)) val opt = bound('{Option(4)}) - println(opt.show) + println(withQuoteContext(opt.show)) println(run(opt)) val map = bound('{Map(4 -> 1)}) - println(map.show) + println(withQuoteContext(map.show)) println(run(map)) } diff --git a/tests/run-with-compiler/i5997.scala b/tests/run-with-compiler/i5997.scala index 84bb27d0e2d5..7fd7856ade42 100644 --- a/tests/run-with-compiler/i5997.scala +++ b/tests/run-with-compiler/i5997.scala @@ -1,6 +1,7 @@ +import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { val v = '{ (if true then Some(1) else None).map(v => v+1) } println(v.show) } diff --git a/tests/run-with-compiler/i6270/Macro_1.scala b/tests/run-with-compiler/i6270/Macro_1.scala index a6a9020833b6..4ffeb31078e6 100644 --- a/tests/run-with-compiler/i6270/Macro_1.scala +++ b/tests/run-with-compiler/i6270/Macro_1.scala @@ -1,4 +1,5 @@ import scala.quoted._ +import scala.quoted.show.SyntaxHighlight.ANSI import scala.tasty._ object api { @@ -7,7 +8,7 @@ object api { private def reflImpl(x: Expr[String])(implicit refl: Reflection): Expr[String] = { import refl._ - x.show(the[Context].withoutColors).toExpr + x.show.toExpr } inline def (x: => String) reflectColor : String = @@ -15,6 +16,6 @@ object api { private def reflImplColor(x: Expr[String])(implicit refl: Reflection): Expr[String] = { import refl._ - x.show(the[Context].withColors).toExpr + x.show(ANSI).toExpr } } diff --git a/tests/run-with-compiler/quote-function-applied-to.scala b/tests/run-with-compiler/quote-function-applied-to.scala index 8720ff612417..c9c6cc2f95d8 100644 --- a/tests/run-with-compiler/quote-function-applied-to.scala +++ b/tests/run-with-compiler/quote-function-applied-to.scala @@ -1,54 +1,55 @@ -import quoted._ +import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - 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 show(expr: Expr[_]): String = withQuoteContext(expr.show) + println(show(('{ () => x(0) }).apply())) + println(show(('{ (x1: Int) => x1 }).apply('{x(1)}))) + println(show(('{ (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 }).apply('{x(1)}, '{x(2)}, '{x(3)}))) + println(show(('{ (x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) + println(show(('{ (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)}))) - 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) + println(show(('{ given (x1: Int) => x1 }).apply('{x(1)}))) + println(show(('{ given (x1: Int, x2: Int) => x1 + x2 }).apply('{x(1)}, '{x(2)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int) => x1 + x2 + x3 }).apply('{x(1)}, '{x(2)}, '{x(3)}))) + println(show(('{ given (x1: Int, x2: Int, x3: Int, x4: Int) => x1 + x2 + x3 + x4 }).apply('{x(1)}, '{x(2)}, '{x(3)}, '{x(4)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) + println(show(('{ 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)}))) } def x(i: Int): Int = i diff --git a/tests/run-with-compiler/quote-lib.scala b/tests/run-with-compiler/quote-lib.scala index 0db100f12028..0c5c58d21d3b 100644 --- a/tests/run-with-compiler/quote-lib.scala +++ b/tests/run-with-compiler/quote-lib.scala @@ -10,8 +10,8 @@ import liftable.Lists._ import liftable.Exprs._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { val liftedUnit: Expr[Unit] = '{} letVal('{1})(a => '{ $a + 1 }).show @@ -36,6 +36,7 @@ object Test { list.unrolledForeach('{ (x: Int) => println(x) }).show println("quote lib ok") + '{} } } diff --git a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala index e2625c0a9388..65a2480738f0 100644 --- a/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala +++ b/tests/run-with-compiler/quote-macro-in-splice/quoted_2.scala @@ -2,8 +2,8 @@ import scala.quoted._ import Macros._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { val x = '{ val y = 1 ${ diff --git a/tests/run-with-compiler/quote-nested-1.scala b/tests/run-with-compiler/quote-nested-1.scala index 78b4c52e7508..e9be760bea3c 100644 --- a/tests/run-with-compiler/quote-nested-1.scala +++ b/tests/run-with-compiler/quote-nested-1.scala @@ -4,6 +4,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = '{ '{3} } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-2.scala b/tests/run-with-compiler/quote-nested-2.scala index 6d5eca0029fd..d7b638296ddf 100644 --- a/tests/run-with-compiler/quote-nested-2.scala +++ b/tests/run-with-compiler/quote-nested-2.scala @@ -1,14 +1,14 @@ import quoted._ object Test { + def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val q = '{ val a = '{4} '{${a}} } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-3.scala b/tests/run-with-compiler/quote-nested-3.scala index 827ce44d5cd2..30d0a40b8d76 100644 --- a/tests/run-with-compiler/quote-nested-3.scala +++ b/tests/run-with-compiler/quote-nested-3.scala @@ -1,9 +1,9 @@ import quoted._ object Test { + def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val q = '{ type T = String val x = "foo" @@ -14,6 +14,6 @@ object Test { x } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-4.scala b/tests/run-with-compiler/quote-nested-4.scala index 850095f2ace3..fbbb9a3fc79e 100644 --- a/tests/run-with-compiler/quote-nested-4.scala +++ b/tests/run-with-compiler/quote-nested-4.scala @@ -9,6 +9,6 @@ object Test { t } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-nested-5.scala b/tests/run-with-compiler/quote-nested-5.scala index 3ba3f6a43bd1..4c8e7ba30c58 100644 --- a/tests/run-with-compiler/quote-nested-5.scala +++ b/tests/run-with-compiler/quote-nested-5.scala @@ -12,6 +12,6 @@ object Test { } - println(q.show) + println(withQuoteContext(q.show)) } } diff --git a/tests/run-with-compiler/quote-owners-2.check b/tests/run-with-compiler/quote-owners-2.check index 847c2e2d84e1..fc038fc486a3 100644 --- a/tests/run-with-compiler/quote-owners-2.check +++ b/tests/run-with-compiler/quote-owners-2.check @@ -1,7 +1,6 @@ -3 { def ff: scala.Int = { - val a: scala.collection.immutable.List[scala.Int] = { + val a: scala.List[scala.Int] = { type T = scala.List[scala.Int] val b: T = scala.Nil.::[scala.Int](3) @@ -13,3 +12,4 @@ (ff: scala.Int) } +3 diff --git a/tests/run-with-compiler/quote-owners-2.scala b/tests/run-with-compiler/quote-owners-2.scala index 6ead29442eba..030db133a456 100644 --- a/tests/run-with-compiler/quote-owners-2.scala +++ b/tests/run-with-compiler/quote-owners-2.scala @@ -2,11 +2,11 @@ import quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { val q = f(g(Type.IntTag)) - println(run(q)) println(q.show) + '{ println($q) } } def f(t: Type[List[Int]]): Expr[Int] = '{ diff --git a/tests/run-with-compiler/quote-owners.scala b/tests/run-with-compiler/quote-owners.scala index 9811c4bcebde..9149678d64dc 100644 --- a/tests/run-with-compiler/quote-owners.scala +++ b/tests/run-with-compiler/quote-owners.scala @@ -5,7 +5,7 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) val q = f println(run(q)) - println(q.show) + println(withQuoteContext(q.show)) } def f: Expr[Int] = '{ diff --git a/tests/run-with-compiler/quote-run-2.check b/tests/run-with-compiler/quote-run-2.check index 0821d5fb001e..7e9019bb7aa9 100644 --- a/tests/run-with-compiler/quote-run-2.check +++ b/tests/run-with-compiler/quote-run-2.check @@ -11,11 +11,11 @@ { val y: scala.Double = 5.0.*(5.0) y.*({ - val y$2: scala.Double = y.*(y) - y$2.*({ - val y$3: scala.Double = y$2.*(y$2) - val y$4: scala.Double = y$3.*(y$3) - y$4 + val y: scala.Double = y.*(y) + y.*({ + val y: scala.Double = y.*(y) + val y: scala.Double = y.*(y) + y }) }) } diff --git a/tests/run-with-compiler/quote-run-2.scala b/tests/run-with-compiler/quote-run-2.scala index 25e527baaafb..00f8ceb5409a 100644 --- a/tests/run-with-compiler/quote-run-2.scala +++ b/tests/run-with-compiler/quote-run-2.scala @@ -2,8 +2,8 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = withQuoteContext { def powerCode(n: Int, x: Expr[Double]): Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x diff --git a/tests/run-with-compiler/quote-run-constants.scala b/tests/run-with-compiler/quote-run-constants.scala index b69247dcd3f8..63dab930879f 100644 --- a/tests/run-with-compiler/quote-run-constants.scala +++ b/tests/run-with-compiler/quote-run-constants.scala @@ -7,7 +7,6 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) def runAndPrint[T](expr: Expr[T]): Unit = println(run(expr)) - def show[T](expr: Expr[T]): Unit = println(expr.show) runAndPrint(true) runAndPrint('a') @@ -24,20 +23,25 @@ object Test { println("======") - show(true) - show('a') - show('\n') - show('"') - show('\'') - show('\\') - show(1) - show(2) - show(3L) - show(4.0f) - show(5.0d) - show("xyz") - show("\n\\\"'") - show("""abc + withQuoteContext { + def show[T](expr: Expr[T]): Unit = println(expr.show) + + show(true) + show('a') + show('\n') + show('"') + show('\'') + show('\\') + show(1) + show(2) + show(3L) + show(4.0f) + show(5.0d) + show("xyz") + show("\n\\\"'") + show( + """abc xyz""") + } } } diff --git a/tests/run-with-compiler/quote-run-large.check b/tests/run-with-compiler/quote-run-large.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/run-with-compiler/quote-run-large.scala b/tests/run-with-compiler/quote-run-large.scala index 043f549ef05a..fc6961c741ea 100644 --- a/tests/run-with-compiler/quote-run-large.scala +++ b/tests/run-with-compiler/quote-run-large.scala @@ -1,3 +1,4 @@ +import scala.quoted._ object Test { def main(args: Array[String]): Unit = { @@ -61,6 +62,9 @@ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) assert(a.asInstanceOf[scala.internal.quoted.TastyExpr[_]].tasty.size > 1, "Test should be testing a quote with TastyExpr encoded in more than one string") - a.show // Force unpiclking of the expression + run { + a.show// Force unpiclking of the expression + '{} + } } -} \ No newline at end of file +} diff --git a/tests/run-with-compiler/quote-run-staged-interpreter.scala b/tests/run-with-compiler/quote-run-staged-interpreter.scala index e6babd0f6287..59745f099865 100644 --- a/tests/run-with-compiler/quote-run-staged-interpreter.scala +++ b/tests/run-with-compiler/quote-run-staged-interpreter.scala @@ -34,7 +34,7 @@ object Test { val res1 = '{ (x: Int) => ${compile(exp, Map("x" -> 'x), false)} } - println(res1.show) + println(withQuoteContext(res1.show)) val fn = run { res1 @@ -46,17 +46,13 @@ object Test { println("---") val res2 = compile(letExp, Map(), false) - println(res2.show) - println(run { - res2 - }) + println(withQuoteContext(res2.show)) + println(run(res2)) println("---") val res3 = compile(letExp, Map(), true) - println(res3.show) - println(run { - res3 - }) + println(withQuoteContext(res3.show)) + println(run(res3)) } } diff --git a/tests/run-with-compiler/quote-run-with-settings.scala b/tests/run-with-compiler/quote-run-with-settings.scala index a77029c9f349..ca0b66a28ec4 100644 --- a/tests/run-with-compiler/quote-run-with-settings.scala +++ b/tests/run-with-compiler/quote-run-with-settings.scala @@ -11,7 +11,7 @@ object Test { println("foo") 2 + a } - println(expr.show) + println(withQuoteContext(expr.show)) println(run(expr)) println() diff --git a/tests/run-with-compiler/quote-run.scala b/tests/run-with-compiler/quote-run.scala index b0d4fa33702b..d28e3b8e1fa4 100644 --- a/tests/run-with-compiler/quote-run.scala +++ b/tests/run-with-compiler/quote-run.scala @@ -10,6 +10,6 @@ object Test { } println(run(expr)) println(run(expr)) - println(expr.show) + println(withQuoteContext(expr.show)) } } diff --git a/tests/run-with-compiler/quote-show-blocks.scala b/tests/run-with-compiler/quote-show-blocks.scala index c5fb45d1ce3a..6128ac86321f 100644 --- a/tests/run-with-compiler/quote-show-blocks.scala +++ b/tests/run-with-compiler/quote-show-blocks.scala @@ -2,8 +2,8 @@ import scala.quoted._ import scala.quoted.autolift._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { def a(n: Int, x: Expr[Unit]): Expr[Unit] = if (n == 0) x else a(n - 1, '{ println(${n}); $x }) @@ -16,6 +16,7 @@ object Test { else b(n - 1, '{ $x; println(${n}) }) println(b(5, '{}).show) + '{} } } diff --git a/tests/run-with-compiler/quote-two-captured-ref.scala b/tests/run-with-compiler/quote-two-captured-ref.scala index 79dea2f4482f..093931d9ac78 100644 --- a/tests/run-with-compiler/quote-two-captured-ref.scala +++ b/tests/run-with-compiler/quote-two-captured-ref.scala @@ -1,8 +1,8 @@ import quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { val q = '{ val x = 1 println(${ @@ -14,5 +14,6 @@ object Test { } println(q.show) + '{} } } diff --git a/tests/run-with-compiler/quote-type-tags.scala b/tests/run-with-compiler/quote-type-tags.scala index 36534c041b03..394efe9edd9d 100644 --- a/tests/run-with-compiler/quote-type-tags.scala +++ b/tests/run-with-compiler/quote-type-tags.scala @@ -1,8 +1,8 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + def main(args: Array[String]): Unit = run { def asof[T: Type, U](x: Expr[T], t: Type[U]): Expr[U] = '{$x.asInstanceOf[$t]} @@ -17,5 +17,6 @@ object Test { println(asof('{5d}, '[Double]).show) println(asof('{5d}, '[Boolean]).show) // Will clearly fail at runtime but the code can be generated + '{} } } diff --git a/tests/run-with-compiler/quote-unrolled-foreach.scala b/tests/run-with-compiler/quote-unrolled-foreach.scala index 89cee178f3cd..260c6ec7dd0d 100644 --- a/tests/run-with-compiler/quote-unrolled-foreach.scala +++ b/tests/run-with-compiler/quote-unrolled-foreach.scala @@ -4,7 +4,7 @@ import scala.quoted.autolift._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def main(args: Array[String]): Unit = { + def main(args: Array[String]): Unit = run { val code1 = '{ (arr: Array[Int], f: Int => Unit) => ${ foreach1('arr, 'f) } } println(code1.show) println() @@ -40,7 +40,7 @@ object Test { } println(printAll(Array(1, 3, 4, 5)).show) - + '{} } def foreach1(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]): Expr[Unit] = '{ diff --git a/tests/run-with-compiler/shonan-hmm-simple.scala b/tests/run-with-compiler/shonan-hmm-simple.scala index 1c486d037d1f..9737d1ed1829 100644 --- a/tests/run-with-compiler/shonan-hmm-simple.scala +++ b/tests/run-with-compiler/shonan-hmm-simple.scala @@ -146,7 +146,7 @@ object Test { vec1.map(_.toExpr), vec2.map(_.toExpr) ) - println(resCode1.show) + println(withQuoteContext(resCode1.show)) println(run(resCode1)) println() @@ -161,7 +161,7 @@ object Test { ) } } - println(resCode2.show) + println(withQuoteContext(resCode2.show)) println(run(resCode2).apply(arr1, arr2)) println() @@ -170,7 +170,7 @@ object Test { vec1.map(i => Dyn(i)), vec2.map(i => Sta(i)) ).expr - println(resCode3.show) + println(withQuoteContext(resCode3.show)) println(run(resCode3)) println() @@ -186,7 +186,7 @@ object Test { } } - println(resCode4.show) + println(withQuoteContext(resCode4.show)) println(run(resCode4).apply(arr1)) println() @@ -203,7 +203,7 @@ object Test { '{Complex(${cpx.re.expr}, ${cpx.im.expr})} } } - println(resCode5.show) + println(withQuoteContext(resCode5.show)) println(run(resCode5).apply(cmpxArr1)) println() @@ -213,7 +213,7 @@ object Test { // will generate the code '{ ((arr: scala.Array[scala.Int]) => arr.apply(1).+(arr.apply(3))) } val staticVec = Vec[Int, PV[Int]](5, i => Sta((i % 2))) val code = '{(arr: Array[Int]) => ${dotIntOptExpr(Vec(5, i => Dyn('{arr(${i})})), staticVec).expr} } - println(code.show) + println(withQuoteContext(code.show)) println() } diff --git a/tests/run-with-compiler/shonan-hmm.check b/tests/run-with-compiler/shonan-hmm.check index f39b702f17ce..96a41ed3ed51 100644 --- a/tests/run-with-compiler/shonan-hmm.check +++ b/tests/run-with-compiler/shonan-hmm.check @@ -20,10 +20,10 @@ List(25, 30, 20, 43, 44) while (i.<(n)) { vout.update(i, { var sum: scala.Int = 0 - var i$2: scala.Int = 0 - while (i$2.<(m)) { - sum = sum.+(v.apply(i$2).*(a.apply(i).apply(i$2))) - i$2 = i$2.+(1) + var i: scala.Int = 0 + while (i.<(m)) { + sum = sum.+(v.apply(i).*(a.apply(i).apply(i))) + i = i.+(1) } (sum: scala.Int) @@ -48,49 +48,49 @@ List(25, 30, 20, 43, 44) val arr: scala.Array[scala.Array[scala.Int]] = { val array: scala.Array[scala.Array[scala.Int]] = dotty.runtime.Arrays.newGenericArray[scala.Array[scala.Int]](5)(scala.reflect.ClassTag.apply[scala.Array[scala.Int]](scala.Predef.classOf[scala.Array[scala.Int]])) array.update(0, { - val array$2: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$2.update(0, 5) - array$2.update(1, 0) - array$2.update(2, 0) - array$2.update(3, 5) - array$2.update(4, 0) - array$2 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 5) + array.update(1, 0) + array.update(2, 0) + array.update(3, 5) + array.update(4, 0) + array }) array.update(1, { - val array$3: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$3.update(0, 0) - array$3.update(1, 0) - array$3.update(2, 10) - array$3.update(3, 0) - array$3.update(4, 0) - array$3 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 10) + array.update(3, 0) + array.update(4, 0) + array }) array.update(2, { - val array$4: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$4.update(0, 0) - array$4.update(1, 10) - array$4.update(2, 0) - array$4.update(3, 0) - array$4.update(4, 0) - array$4 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 10) + array.update(2, 0) + array.update(3, 0) + array.update(4, 0) + array }) array.update(3, { - val array$5: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$5.update(0, 0) - array$5.update(1, 0) - array$5.update(2, 2) - array$5.update(3, 3) - array$5.update(4, 5) - array$5 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 2) + array.update(3, 3) + array.update(4, 5) + array }) array.update(4, { - val array$6: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$6.update(0, 0) - array$6.update(1, 0) - array$6.update(2, 3) - array$6.update(3, 0) - array$6.update(4, 7) - array$6 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 3) + array.update(3, 0) + array.update(4, 7) + array }) array } @@ -111,49 +111,49 @@ List(25, 30, 20, 43, 44) val arr: scala.Array[scala.Array[scala.Int]] = { val array: scala.Array[scala.Array[scala.Int]] = dotty.runtime.Arrays.newGenericArray[scala.Array[scala.Int]](5)(scala.reflect.ClassTag.apply[scala.Array[scala.Int]](scala.Predef.classOf[scala.Array[scala.Int]])) array.update(0, { - val array$2: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$2.update(0, 5) - array$2.update(1, 0) - array$2.update(2, 0) - array$2.update(3, 5) - array$2.update(4, 0) - array$2 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 5) + array.update(1, 0) + array.update(2, 0) + array.update(3, 5) + array.update(4, 0) + array }) array.update(1, { - val array$3: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$3.update(0, 0) - array$3.update(1, 0) - array$3.update(2, 10) - array$3.update(3, 0) - array$3.update(4, 0) - array$3 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 10) + array.update(3, 0) + array.update(4, 0) + array }) array.update(2, { - val array$4: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$4.update(0, 0) - array$4.update(1, 10) - array$4.update(2, 0) - array$4.update(3, 0) - array$4.update(4, 0) - array$4 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 10) + array.update(2, 0) + array.update(3, 0) + array.update(4, 0) + array }) array.update(3, { - val array$5: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$5.update(0, 0) - array$5.update(1, 0) - array$5.update(2, 2) - array$5.update(3, 3) - array$5.update(4, 5) - array$5 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 2) + array.update(3, 3) + array.update(4, 5) + array }) array.update(4, { - val array$6: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$6.update(0, 0) - array$6.update(1, 0) - array$6.update(2, 3) - array$6.update(3, 0) - array$6.update(4, 7) - array$6 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 3) + array.update(3, 0) + array.update(4, 7) + array }) array } @@ -174,49 +174,49 @@ List(25, 30, 20, 43, 44) val arr: scala.Array[scala.Array[scala.Int]] = { val array: scala.Array[scala.Array[scala.Int]] = dotty.runtime.Arrays.newGenericArray[scala.Array[scala.Int]](5)(scala.reflect.ClassTag.apply[scala.Array[scala.Int]](scala.Predef.classOf[scala.Array[scala.Int]])) array.update(0, { - val array$2: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$2.update(0, 5) - array$2.update(1, 0) - array$2.update(2, 0) - array$2.update(3, 5) - array$2.update(4, 0) - array$2 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 5) + array.update(1, 0) + array.update(2, 0) + array.update(3, 5) + array.update(4, 0) + array }) array.update(1, { - val array$3: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$3.update(0, 0) - array$3.update(1, 0) - array$3.update(2, 10) - array$3.update(3, 0) - array$3.update(4, 0) - array$3 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 10) + array.update(3, 0) + array.update(4, 0) + array }) array.update(2, { - val array$4: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$4.update(0, 0) - array$4.update(1, 10) - array$4.update(2, 0) - array$4.update(3, 0) - array$4.update(4, 0) - array$4 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 10) + array.update(2, 0) + array.update(3, 0) + array.update(4, 0) + array }) array.update(3, { - val array$5: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$5.update(0, 0) - array$5.update(1, 0) - array$5.update(2, 2) - array$5.update(3, 3) - array$5.update(4, 5) - array$5 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 2) + array.update(3, 3) + array.update(4, 5) + array }) array.update(4, { - val array$6: scala.Array[scala.Int] = new scala.Array[scala.Int](5) - array$6.update(0, 0) - array$6.update(1, 0) - array$6.update(2, 3) - array$6.update(3, 0) - array$6.update(4, 7) - array$6 + val array: scala.Array[scala.Int] = new scala.Array[scala.Int](5) + array.update(0, 0) + array.update(1, 0) + array.update(2, 3) + array.update(3, 0) + array.update(4, 7) + array }) array } diff --git a/tests/run-with-compiler/shonan-hmm/Test.scala b/tests/run-with-compiler/shonan-hmm/Test.scala index 44849c6e3abd..2dbe6cc5d488 100644 --- a/tests/run-with-compiler/shonan-hmm/Test.scala +++ b/tests/run-with-compiler/shonan-hmm/Test.scala @@ -4,8 +4,9 @@ import scala.quoted._ object Test { - def main(args: Array[String]): Unit = { - implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + + def main(args: Array[String]): Unit = withQuoteContext { { val intComplex = new RingComplex(RingInt) diff --git a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala index d88a0f0bed63..0d9acbd30ab4 100644 --- a/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala +++ b/tests/run-with-compiler/tasty-extractors-constants-2/quoted_1.scala @@ -11,23 +11,17 @@ object Macros { def impl(implicit reflect: Reflection): Expr[Unit] = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) // 2 is a lifted constant - val show1 = power(2, 3.0).show - val run1 = run { - power(2, 3.0) - } + val show1 = withQuoteContext(power(2, 3.0).show) + val run1 = run(power(2, 3.0)) // n is a lifted constant val n = 2 - val show2 = power(n, 4.0).show - val run2 = run { - power(n, 4.0) - } + val show2 = withQuoteContext(power(n, 4.0).show) + val run2 = run(power(n, 4.0)) // n is a constant in a quote - val show3 = power('{2}, 5.0).show - val run3 = run { - power('{2}, 5.0) - } + val show3 = withQuoteContext(power('{2}, 5.0).show) + val run3 = run(power('{2}, 5.0)) // n2 is clearly not a constant // FIXME