diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 4d8290b88218..31804f36b9cb 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -758,6 +758,7 @@ class Definitions { @threadUnsafe lazy val QuotedExprType: TypeRef = ctx.requiredClassRef("scala.quoted.Expr") def QuotedExprClass(implicit ctx: Context): ClassSymbol = QuotedExprType.symbol.asClass + def QuotedExprModule(implicit ctx: Context): Symbol = QuotedExprClass.companionModule @threadUnsafe lazy val QuoteContextType: TypeRef = ctx.requiredClassRef("scala.quoted.QuoteContext") def QuoteContextClass(implicit ctx: Context): ClassSymbol = QuoteContextType.symbol.asClass @@ -765,6 +766,8 @@ class Definitions { @threadUnsafe lazy val QuoteContextModule: TermSymbol = ctx.requiredModule("scala.quoted.QuoteContext") @threadUnsafe lazy val QuoteContext_macroContext: TermSymbol = QuoteContextModule.requiredMethod("macroContext") + @threadUnsafe lazy val LiftableModule: TermSymbol = ctx.requiredModule("scala.quoted.Liftable") + @threadUnsafe lazy val InternalQuotedModuleRef: TermRef = ctx.requiredModuleRef("scala.internal.Quoted") def InternalQuotedModule: Symbol = InternalQuotedModuleRef.symbol @threadUnsafe lazy val InternalQuoted_exprQuoteR: TermRef = InternalQuotedModule.requiredMethodRef("exprQuote") @@ -797,7 +800,6 @@ class Definitions { def QuotedMatchingBindingClass(implicit ctx: Context): ClassSymbol = QuotedMatchingBindingType.symbol.asClass def Unpickler_unpickleExpr: TermSymbol = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleExpr") - def Unpickler_liftedExpr: TermSymbol = ctx.requiredMethod("scala.runtime.quoted.Unpickler.liftedExpr") def Unpickler_unpickleType: TermSymbol = ctx.requiredMethod("scala.runtime.quoted.Unpickler.unpickleType") @threadUnsafe lazy val TastyReflectionType: TypeRef = ctx.requiredClassRef("scala.tasty.Reflection") diff --git a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala index d33a8580e560..2078184b5571 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala @@ -45,11 +45,6 @@ object PickledQuotes { } } forceAndCleanArtefacts.transform(unpickled) - case expr: LiftedExpr[T] => - expr.value match { - case value: Class[_] => ref(defn.Predef_classOf).appliedToType(classToType(value)) - case value => Literal(Constant(value)) - } case expr: TastyTreeExpr[Tree] @unchecked => healOwner(expr.tree) case expr: FunctionAppliedTo[_] => functionAppliedTo(quotedExprToTree(expr.f), expr.args.map(arg => quotedExprToTree(arg)).toList) @@ -174,29 +169,6 @@ object PickledQuotes { seq(argVals.flatten, rec(fn)) } - private def classToType(clazz: Class[_])(implicit ctx: Context): Type = { - if (clazz.isPrimitive) { - if (clazz == classOf[Boolean]) defn.BooleanType - else if (clazz == classOf[Byte]) defn.ByteType - else if (clazz == classOf[Char]) defn.CharType - else if (clazz == classOf[Short]) defn.ShortType - else if (clazz == classOf[Int]) defn.IntType - else if (clazz == classOf[Long]) defn.LongType - else if (clazz == classOf[Float]) defn.FloatType - else if (clazz == classOf[Double]) defn.DoubleType - else defn.UnitType - } else if (clazz.isArray) { - defn.ArrayType.appliedTo(classToType(clazz.getComponentType)) - } else if (clazz.isMemberClass) { - val name = clazz.getSimpleName.toTypeName - val enclosing = classToType(clazz.getEnclosingClass) - if (enclosing.member(name).exists) enclosing.select(name) - else { - enclosing.classSymbol.companionModule.termRef.select(name) - } - } else ctx.getClassIfDefined(clazz.getCanonicalName).typeRef - } - /** Make sure that the owner of this tree is `ctx.owner` */ private def healOwner(tree: Tree)(implicit ctx: Context): Tree = { val getCurrentOwner = new TreeAccumulator[Option[Symbol]] { diff --git a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala index 7e3ee92c88ea..5ef310a1e60f 100644 --- a/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala +++ b/compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala @@ -49,7 +49,6 @@ class QuoteCompiler extends Compiler { class QuotedFrontend extends Phase { import tpd._ - def phaseName: String = "quotedFrontend" override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = { @@ -65,7 +64,7 @@ class QuoteCompiler extends Compiler { 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)) + val quoted = PickledQuotes.quotedExprToTree(exprUnit.exprBuilder.apply(new QuoteContext(ReflectionImpl(ctx))))(ctx.withOwner(meth)) getLiteral(quoted) match { case Some(value) => @@ -82,12 +81,6 @@ class QuoteCompiler extends Compiler { } } - 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 - } - /** 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) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 0e2dddf69555..3302855a9716 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1055,6 +1055,29 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. case _ => Some(x) } + def Type_apply(clazz: Class[_])(implicit ctx: Context): Type = { + if (clazz.isPrimitive) { + if (clazz == classOf[Boolean]) defn.BooleanType + else if (clazz == classOf[Byte]) defn.ByteType + else if (clazz == classOf[Char]) defn.CharType + else if (clazz == classOf[Short]) defn.ShortType + else if (clazz == classOf[Int]) defn.IntType + else if (clazz == classOf[Long]) defn.LongType + else if (clazz == classOf[Float]) defn.FloatType + else if (clazz == classOf[Double]) defn.DoubleType + else defn.UnitType + } else if (clazz.isArray) { + defn.ArrayType.appliedTo(Type_apply(clazz.getComponentType)) + } else if (clazz.isMemberClass) { + val name = clazz.getSimpleName.toTypeName + val enclosing = Type_apply(clazz.getEnclosingClass) + if (enclosing.member(name).exists) enclosing.select(name) + else { + enclosing.classSymbol.companionModule.termRef.select(name) + } + } else ctx.getClassIfDefined(clazz.getCanonicalName).typeRef + } + def `Type_=:=`(self: Type)(that: Type)(implicit ctx: Context): Boolean = self =:= that def `Type_<:<`(self: Type)(that: Type)(implicit ctx: Context): Boolean = self <:< that @@ -1431,6 +1454,9 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Constant_value(const: Constant): Any = const.value + def matchConstant(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] = + Some(constant.asInstanceOf[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type]) + def matchConstant_Unit(x: Constant): Boolean = x.tag == Constants.UnitTag def matchConstant_Null(x: Constant): Boolean = x.tag == Constants.NullTag def matchConstant_Boolean(x: Constant): Option[Boolean] = @@ -1454,6 +1480,9 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def matchConstant_ClassTag(x: Constant): Option[Type] = if (x.tag == Constants.ClazzTag) Some(x.typeValue) else None + def Constant_apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant = + Constants.Constant(x) + def Constant_Unit_apply(): Constant = Constants.Constant(()) def Constant_Null_apply(): Constant = Constants.Constant(null) def Constant_Boolean_apply(x: Boolean): Constant = Constants.Constant(x) @@ -1809,6 +1838,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Definitions_ClassClass: Symbol = defn.ClassClass def Definitions_ArrayClass: Symbol = defn.ArrayClass def Definitions_PredefModule: Symbol = defn.ScalaPredefModule.asTerm + def Definitions_Predef_classOf: Symbol = defn.Predef_classOf.asTerm def Definitions_JavaLangPackage: Symbol = defn.JavaLangPackageVal diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 32967981b72e..3e28b4a12ffb 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -20,6 +20,7 @@ import typer.Implicits.SearchFailureType import scala.collection.mutable import dotty.tools.dotc.core.Annotations.Annotation +import dotty.tools.dotc.core.Names._ import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.core.quoted._ import dotty.tools.dotc.transform.TreeMapWithStages._ @@ -71,6 +72,8 @@ class ReifyQuotes extends MacroTransform { override def phaseName: String = ReifyQuotes.name + override def allowsImplicitSearch: Boolean = true + override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = { tree match { case tree: RefTree if !ctx.inInlineMethod => @@ -199,8 +202,29 @@ class ReifyQuotes extends MacroTransform { } private def pickledQuote(body: Tree, splices: List[Tree], originalTp: Type, isType: Boolean)(implicit ctx: Context) = { - def pickleAsValue[T](value: T) = - ref(defn.Unpickler_liftedExpr).appliedToType(originalTp.widen).appliedTo(Literal(Constant(value))) + + def liftedValue[T](value: T, name: TermName, qctx: Tree) = + ref(defn.LiftableModule).select(name).select("toExpr".toTermName).appliedTo(Literal(Constant(value))).appliedTo(qctx) + + def pickleAsValue[T](value: T) = { + val qctx = ctx.typer.inferImplicitArg(defn.QuoteContextType, body.span) + if (qctx.tpe.isInstanceOf[SearchFailureType]) + ctx.error(ctx.typer.missingArgMsg(qctx, defn.QuoteContextType, ""), ctx.source.atSpan(body.span)) + value match { + case null => ref(defn.QuotedExprModule).select("nullExpr".toTermName).appliedTo(qctx) + case _: Unit => ref(defn.QuotedExprModule).select("unitExpr".toTermName).appliedTo(qctx) + case _: Boolean => liftedValue(value, "Liftable_Boolean_delegate".toTermName, qctx) + case _: Byte => liftedValue(value, "Liftable_Byte_delegate".toTermName, qctx) + case _: Short => liftedValue(value, "Liftable_Short_delegate".toTermName, qctx) + case _: Int => liftedValue(value, "Liftable_Int_delegate".toTermName, qctx) + case _: Long => liftedValue(value, "Liftable_Long_delegate".toTermName, qctx) + case _: Float => liftedValue(value, "Liftable_Float_delegate".toTermName, qctx) + case _: Double => liftedValue(value, "Liftable_Double_delegate".toTermName, qctx) + case _: Char => liftedValue(value, "Liftable_Char_delegate".toTermName, qctx) + case _: String => liftedValue(value, "Liftable_String_delegate".toTermName, qctx) + } + } + def pickleAsTasty() = { val meth = if (isType) ref(defn.Unpickler_unpickleType).appliedToType(originalTp) diff --git a/library/src-3.x/scala/quoted/Expr.scala b/library/src-3.x/scala/quoted/Expr.scala index 6f5472ad129a..7b89930eab43 100644 --- a/library/src-3.x/scala/quoted/Expr.scala +++ b/library/src-3.x/scala/quoted/Expr.scala @@ -44,7 +44,19 @@ package quoted { tg.untupled(args => new FunctionAppliedTo[R](f, args.toArray.map(_.asInstanceOf[Expr[_]]))) } - /** Returns A expression containing a block with the given statements and ending with the expresion + /** Returns a null expresssion equivalent to `'{null}` */ + def nullExpr given (qctx: QuoteContext): Expr[Null] = { + import qctx.tasty._ + Literal(Constant(null)).seal.asInstanceOf[Expr[Null]] + } + + /** Returns a unit expresssion equivalent to `'{}` or `'{()}` */ + def unitExpr given (qctx: QuoteContext): Expr[Unit] = { + import qctx.tasty._ + Literal(Constant(())).seal.asInstanceOf[Expr[Unit]] + } + + /** Returns an expression containing a block with the given statements and ending with the expresion * Given list of statements `s1 :: s2 :: ... :: Nil` and an expression `e` the resulting expression * will be equivalent to `'{ $s1; $s2; ...; $e }`. */ @@ -67,13 +79,6 @@ package internal { override def toString: String = s"Expr()" } - /** An Expr backed by a lifted value. - * Values can only be of type Boolean, Byte, Short, Char, Int, Long, Float, Double, Unit, String or Null. - */ - final class LiftedExpr[+T](val value: T) extends Expr[T] { - override def toString: String = s"Expr($value)" - } - /** An Expr backed by a tree. Only the current compiler trees are allowed. * * These expressions are used for arguments of macros. They contain and actual tree diff --git a/library/src-3.x/scala/quoted/Liftable.scala b/library/src-3.x/scala/quoted/Liftable.scala index 63ab24dc1cf6..f29398622ba6 100644 --- a/library/src-3.x/scala/quoted/Liftable.scala +++ b/library/src-3.x/scala/quoted/Liftable.scala @@ -1,12 +1,13 @@ package scala.quoted -import scala.runtime.quoted.Unpickler.liftedExpr - /** A typeclass for types that can be turned to `quoted.Expr[T]` * without going through an explicit `'{...}` operation. */ -abstract class Liftable[T] { +trait Liftable[T] { + + /** Lift a value into an expression containing the construction of that value */ def toExpr(x: T) given QuoteContext: Expr[T] + } /** Some liftable base types. To be completed with at least all types @@ -17,6 +18,7 @@ abstract class Liftable[T] { object Liftable { implicit val Liftable_Boolean_delegate: Liftable[Boolean] = new PrimitiveLiftable + implicit val Liftable_Byte_delegate: Liftable[Byte] = new PrimitiveLiftable implicit val Liftable_Short_delegate: Liftable[Short] = new PrimitiveLiftable implicit val Liftable_Int_delegate: Liftable[Int] = new PrimitiveLiftable implicit val Liftable_Long_delegate: Liftable[Long] = new PrimitiveLiftable @@ -24,10 +26,21 @@ object Liftable { implicit val Liftable_Double_delegate: Liftable[Double] = new PrimitiveLiftable implicit val Liftable_Char_delegate: Liftable[Char] = new PrimitiveLiftable implicit val Liftable_String_delegate: Liftable[String] = new PrimitiveLiftable - implicit def ClassIsLiftable[T]: Liftable[Class[T]] = new PrimitiveLiftable - private class PrimitiveLiftable[T] extends Liftable[T] { - override def toExpr(x: T) given QuoteContext: Expr[T] = liftedExpr(x) + private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] { + /** Lift a primitive value `n` into `'{ n }` */ + def toExpr(x: T) given (qctx: QuoteContext): Expr[T] = { + import qctx.tasty._ + Literal(Constant(x)).seal.asInstanceOf[Expr[T]] + } + } + + implicit def ClassIsLiftable[T]: Liftable[Class[T]] = new Liftable[Class[T]] { + /** Lift a `Class[T]` into `'{ classOf[T] }` */ + def toExpr(x: Class[T]) given (qctx: QuoteContext): Expr[Class[T]] = { + import qctx.tasty._ + Ref(definitions.Predef_classOf).appliedToType(Type(x)).seal.asInstanceOf[Expr[Class[T]]] + } } } diff --git a/library/src-3.x/scala/quoted/package.scala b/library/src-bootstrapped/scala/quoted/package.scala similarity index 100% rename from library/src-3.x/scala/quoted/package.scala rename to library/src-bootstrapped/scala/quoted/package.scala diff --git a/library/src-non-bootstrapped/scala/quoted/package.scala b/library/src-non-bootstrapped/scala/quoted/package.scala new file mode 100644 index 000000000000..aa724ad6f937 --- /dev/null +++ b/library/src-non-bootstrapped/scala/quoted/package.scala @@ -0,0 +1,11 @@ +package scala + +package object quoted { + + def run[T](expr: given QuoteContext => Expr[T]) given (toolbox: Toolbox): T = + throw new Exception("Non bootsrapped library") + + def withQuoteContext[T](thunk: given QuoteContext => T) given (toolbox: Toolbox): T = + throw new Exception("Non bootsrapped library") + +} diff --git a/library/src/scala/runtime/quoted/Unpickler.scala b/library/src/scala/runtime/quoted/Unpickler.scala index 1d261de2fb6b..63eea27617e1 100644 --- a/library/src/scala/runtime/quoted/Unpickler.scala +++ b/library/src/scala/runtime/quoted/Unpickler.scala @@ -1,6 +1,6 @@ package scala.runtime.quoted -import scala.internal.quoted.{LiftedExpr, TastyExpr, TastyType} +import scala.internal.quoted.{TastyExpr, TastyType} import scala.quoted.{Expr, Type} /** Provides methods to unpickle `Expr` and `Type` trees. */ @@ -16,11 +16,6 @@ object Unpickler { */ def unpickleExpr[T](repr: Pickled, args: Seq[Any]): Expr[T] = new TastyExpr[T](repr, args) - /** Lift the `value` to an `Expr` tree. - * Values can only be of type Boolean, Byte, Short, Char, Int, Long, Float, Double, Unit, String, Null or Class. - */ - def liftedExpr[T](value: T): Expr[T] = new LiftedExpr[T](value) - /** Unpickle `repr` which represents a pickled `Type` tree, * replacing splice nodes with `args` */ diff --git a/library/src/scala/tasty/reflect/ConstantOps.scala b/library/src/scala/tasty/reflect/ConstantOps.scala index 98585d52ac38..4b46817c7998 100644 --- a/library/src/scala/tasty/reflect/ConstantOps.scala +++ b/library/src/scala/tasty/reflect/ConstantOps.scala @@ -10,6 +10,14 @@ trait ConstantOps extends Core { /** Module of Constant literals */ object Constant { + def apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant = + kernel.Constant_apply(x) + + def unapply(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] = + kernel.matchConstant(constant) + + // TODO remove all extractors bellow and use only use the two above + /** Module of Null literals */ object Unit { /** Unit `()` literal */ diff --git a/library/src/scala/tasty/reflect/Kernel.scala b/library/src/scala/tasty/reflect/Kernel.scala index cd9df6e059a4..aa795101b2c5 100644 --- a/library/src/scala/tasty/reflect/Kernel.scala +++ b/library/src/scala/tasty/reflect/Kernel.scala @@ -829,6 +829,8 @@ trait Kernel { def matchType(x: TypeOrBounds)(implicit ctx: Context): Option[Type] + def Type_apply(clazz: Class[_])(implicit ctx: Context): Type + def `Type_=:=`(self: Type)(that: Type)(implicit ctx: Context): Boolean def `Type_<:<`(self: Type)(that: Type)(implicit ctx: Context): Boolean @@ -1176,6 +1178,7 @@ trait Kernel { def Constant_value(const: Constant): Any + def matchConstant(constant: Constant): Option[Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type] def matchConstant_Unit(constant: Constant): Boolean def matchConstant_Null(constant: Constant): Boolean def matchConstant_Boolean(constant: Constant): Option[Boolean] @@ -1189,6 +1192,7 @@ trait Kernel { def matchConstant_String(constant: Constant): Option[String] def matchConstant_ClassTag(constant: Constant): Option[Type] + def Constant_apply(x: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String | Type): Constant def Constant_Unit_apply(): Constant def Constant_Null_apply(): Constant def Constant_Boolean_apply(x: Boolean): Constant @@ -1470,6 +1474,7 @@ trait Kernel { def Definitions_ClassClass: Symbol def Definitions_ArrayClass: Symbol def Definitions_PredefModule: Symbol + def Definitions_Predef_classOf: Symbol def Definitions_JavaLangPackage: Symbol diff --git a/library/src/scala/tasty/reflect/StandardDefinitions.scala b/library/src/scala/tasty/reflect/StandardDefinitions.scala index 6b9cf49ced9a..05b199081381 100644 --- a/library/src/scala/tasty/reflect/StandardDefinitions.scala +++ b/library/src/scala/tasty/reflect/StandardDefinitions.scala @@ -85,6 +85,9 @@ trait StandardDefinitions extends Core { /** The module symbol of module `scala.Predef`. */ def PredefModule: Symbol = kernel.Definitions_PredefModule + /** The method symbol of method `scala.Predef.classOf`. */ + def Predef_classOf: Symbol = kernel.Definitions_Predef_classOf + /** The module symbol of package `java.lang`. */ def JavaLangPackage: Symbol = kernel.Definitions_JavaLangPackage diff --git a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala index 69a5e6a05eca..f095d52e29dc 100644 --- a/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala +++ b/library/src/scala/tasty/reflect/TypeOrBoundsOps.scala @@ -64,6 +64,8 @@ trait TypeOrBoundsOps extends Core { object Type { + def apply(clazz: Class[_])(implicit ctx: Context): Type = kernel.Type_apply(clazz) + object IsConstantType { /** Matches any ConstantType and returns it */ def unapply(tpe: TypeOrBounds)(implicit ctx: Context): Option[ConstantType] = diff --git a/tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala b/tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala similarity index 100% rename from tests/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala rename to tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_1.scala diff --git a/tests/neg-with-compiler/quote-run-in-macro-2/quoted_2.scala b/tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_2.scala similarity index 100% rename from tests/neg-with-compiler/quote-run-in-macro-2/quoted_2.scala rename to tests/disabled/neg-with-compiler/quote-run-in-macro-2/quoted_2.scala diff --git a/tests/neg-macros/quote-error-2/Macro_1.scala b/tests/neg-macros/quote-error-2/Macro_1.scala index f6507f10e49c..08c98401fd6a 100644 --- a/tests/neg-macros/quote-error-2/Macro_1.scala +++ b/tests/neg-macros/quote-error-2/Macro_1.scala @@ -2,10 +2,10 @@ import quoted._ object Macro_1 { inline def foo(inline b: Boolean): Unit = ${ fooImpl(b) } - def fooImpl(b: Boolean): Expr[Unit] = + def fooImpl(b: Boolean) given QuoteContext: Expr[Unit] = '{println(${msg(b)})} - def msg(b: Boolean): Expr[String] = + def msg(b: Boolean) given QuoteContext: Expr[String] = if (b) '{"foo(true)"} else QuoteError("foo cannot be called with false") diff --git a/tests/neg-macros/quote-whitebox/Macro_1.scala b/tests/neg-macros/quote-whitebox/Macro_1.scala index 11eb26bf60df..c86c63cbb2e6 100644 --- a/tests/neg-macros/quote-whitebox/Macro_1.scala +++ b/tests/neg-macros/quote-whitebox/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macros { inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl(str) } - def defaultOfImpl(str: String): Expr[Any] = str match { + def defaultOfImpl(str: String) given QuoteContext: Expr[Any] = str match { case "int" => '{1} case "string" => '{"a"} } diff --git a/tests/pos-macros/i3898/quoted_1.scala b/tests/pos-macros/i3898/quoted_1.scala index 8d2b3d2c5d87..7fa50496c38e 100644 --- a/tests/pos-macros/i3898/quoted_1.scala +++ b/tests/pos-macros/i3898/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff(args: Any*): String = ${impl('args)} - def impl(args: Expr[Seq[Any]]): Expr[String] = '{""} + def impl(args: Expr[Seq[Any]]) given QuoteContext: Expr[String] = '{""} } diff --git a/tests/pos-macros/i3898b/quoted_1.scala b/tests/pos-macros/i3898b/quoted_1.scala index fa05e2fc2f93..9598cb78d71a 100644 --- a/tests/pos-macros/i3898b/quoted_1.scala +++ b/tests/pos-macros/i3898b/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff(x: Int, inline y: Int): String = ${impl('x)} - def impl(x: Expr[Int]): Expr[String] = '{""} + def impl(x: Expr[Int]) given QuoteContext: Expr[String] = '{""} } diff --git a/tests/pos-macros/i3898c/quoted_1.scala b/tests/pos-macros/i3898c/quoted_1.scala index fa05e2fc2f93..9598cb78d71a 100644 --- a/tests/pos-macros/i3898c/quoted_1.scala +++ b/tests/pos-macros/i3898c/quoted_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff(x: Int, inline y: Int): String = ${impl('x)} - def impl(x: Expr[Int]): Expr[String] = '{""} + def impl(x: Expr[Int]) given QuoteContext: Expr[String] = '{""} } diff --git a/tests/pos-macros/i3912-1/i3912_1.scala b/tests/pos-macros/i3912-1/i3912_1.scala index faa6c82a4ca8..8e67b72b73b4 100644 --- a/tests/pos-macros/i3912-1/i3912_1.scala +++ b/tests/pos-macros/i3912-1/i3912_1.scala @@ -3,5 +3,5 @@ import scala.quoted._ object Macros { inline def foo(): Int = { ${ impl() } } - def impl(): Expr[Int] = '{1} + def impl() given QuoteContext: Expr[Int] = '{1} } \ No newline at end of file diff --git a/tests/pos-macros/i3912-2/i3912_1.scala b/tests/pos-macros/i3912-2/i3912_1.scala index b6912a6efa74..b359c5baa784 100644 --- a/tests/pos-macros/i3912-2/i3912_1.scala +++ b/tests/pos-macros/i3912-2/i3912_1.scala @@ -3,5 +3,5 @@ import scala.quoted._ object Macros { inline def foo2(): Unit = ${ impl() } - def impl(): Expr[Int] = '{1} + def impl() given QuoteContext: Expr[Int] = '{1} } \ No newline at end of file diff --git a/tests/pos-macros/i4023b/Macro_1.scala b/tests/pos-macros/i4023b/Macro_1.scala index bad8763aeeb2..87959759521b 100644 --- a/tests/pos-macros/i4023b/Macro_1.scala +++ b/tests/pos-macros/i4023b/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff[T](implicit t: Type[T]): Int = ${ impl[T] } - def impl[T]: Expr[Int] = '{4} + def impl[T] given QuoteContext: Expr[Int] = '{4} } diff --git a/tests/pos-macros/macro-with-type/Macro_1.scala b/tests/pos-macros/macro-with-type/Macro_1.scala index c515c8a51ccc..a327c80142fd 100644 --- a/tests/pos-macros/macro-with-type/Macro_1.scala +++ b/tests/pos-macros/macro-with-type/Macro_1.scala @@ -1,5 +1,5 @@ import scala.quoted._ object Macro { inline def ff: Unit = ${impl('[Int])} - def impl(t: Type[Int]): Expr[Unit] = '{} + def impl(t: Type[Int]) given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/pos-macros/power-macro/Macro_1.scala b/tests/pos-macros/power-macro/Macro_1.scala index 53179247dd66..94c5e3175b40 100644 --- a/tests/pos-macros/power-macro/Macro_1.scala +++ b/tests/pos-macros/power-macro/Macro_1.scala @@ -1,11 +1,11 @@ -import scala.quoted.Expr +import scala.quoted._ object PowerMacro { inline def power(inline n: Long, x: Double) = ${powerCode(n, 'x)} - def powerCode(n: Long, x: Expr[Double]): Expr[Double] = + def powerCode(n: Long, x: Expr[Double]) given QuoteContext: Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } else '{ $x * ${powerCode(n - 1, x)} } diff --git a/tests/pos/i3912-3/i3912_1.scala b/tests/pos/i3912-3/i3912_1.scala index c1df47e41db6..6eac5ce2a71b 100644 --- a/tests/pos/i3912-3/i3912_1.scala +++ b/tests/pos/i3912-3/i3912_1.scala @@ -7,5 +7,5 @@ object Macros { } } - def impl(): Expr[Int] = '{1} + def impl() given QuoteContext: Expr[Int] = '{1} } \ No newline at end of file diff --git a/tests/pos/i4380b.scala b/tests/pos/i4380b.scala index 864d02d21885..a5d83e4f2829 100644 --- a/tests/pos/i4380b.scala +++ b/tests/pos/i4380b.scala @@ -1,6 +1,7 @@ import scala.quoted._ object Test { + delegate for QuoteContext = ??? def step(k: (String => Expr[Unit])): Expr[Unit] = '{} def meth(): Unit = '{ (i: Int) => ${ step(el => '{} ) } diff --git a/tests/pos/i4514.scala b/tests/pos/i4514.scala index 97388c9334f8..3054d7d6486f 100644 --- a/tests/pos/i4514.scala +++ b/tests/pos/i4514.scala @@ -1,4 +1,5 @@ +import scala.quoted._ object Foo { inline def foo[X](x: X): Unit = ${fooImpl('x)} - def fooImpl[X: quoted.Type](x: X): quoted.Expr[Unit] = '{} + def fooImpl[X: Type](x: X) given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/pos/i4773.scala b/tests/pos/i4773.scala index 63e73f910586..8db4b510b652 100644 --- a/tests/pos/i4773.scala +++ b/tests/pos/i4773.scala @@ -2,6 +2,6 @@ import scala.quoted._ object Foo { inline def foo2(): Unit = ${foo2Impl()} - def foo2Impl(): Expr[Unit] = '{} + def foo2Impl() given QuoteContext: Expr[Unit] = '{} inline def foo(): Unit = foo2() } diff --git a/tests/pos/i6783.scala b/tests/pos/i6783.scala index e8945ec135be..80e1dbbbcf3b 100644 --- a/tests/pos/i6783.scala +++ b/tests/pos/i6783.scala @@ -1,6 +1,6 @@ import scala.quoted._ -def testImpl(f: Expr[(Int, Int) => Int]): Expr[Int] = f('{1}, '{2}) +def testImpl(f: Expr[(Int, Int) => Int]) given QuoteContext: Expr[Int] = f('{1}, '{2}) inline def test(f: (Int, Int) => Int) = ${ testImpl('f) diff --git a/tests/pos/quote-1.scala b/tests/pos/quote-1.scala index 5772b7d49c1e..32239b45d119 100644 --- a/tests/pos/quote-1.scala +++ b/tests/pos/quote-1.scala @@ -1,6 +1,7 @@ import scala.quoted._ object Test { + delegate for QuoteContext = ??? def f[T](x: Expr[T])(implicit t: Type[T]) = '{ val y: $t = $x @@ -8,7 +9,7 @@ object Test { } f('{2})('[Int]) - f('{ true })('[Boolean]) + f('{ true })('[Boolean]) def g(es: Expr[String], t: Type[String]) = f('{ ($es + "!") :: Nil })('[List[$t]]) diff --git a/tests/pos/quote-nested.scala b/tests/pos/quote-nested.scala index ed5d86d26fa2..4694a4dd3d3d 100644 --- a/tests/pos/quote-nested.scala +++ b/tests/pos/quote-nested.scala @@ -5,7 +5,7 @@ object Macro { inline def foo: Unit = ${ nested() } - private def nested(): Expr[Unit] = '{ + private def nested() given QuoteContext: Expr[Unit] = '{ var i = 0 ${ val x: Expr[Double] = '{ diff --git a/tests/pos/quote-non-static-macro.scala b/tests/pos/quote-non-static-macro.scala index 5b2bcb19a05d..07c63f024877 100644 --- a/tests/pos/quote-non-static-macro.scala +++ b/tests/pos/quote-non-static-macro.scala @@ -14,5 +14,5 @@ object Foo { object Quox { inline def foo: Unit = ${Foo.impl} } - def impl: Expr[Unit] = '{} + def impl given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/pos/quote-this.scala b/tests/pos/quote-this.scala index b06e30b29b69..90a164442ef2 100644 --- a/tests/pos/quote-this.scala +++ b/tests/pos/quote-this.scala @@ -1,19 +1,19 @@ import scala.quoted._ class Foo { - def a: Expr[Int] = '{1} - def b: Expr[Int] = '{ + def a given QuoteContext: Expr[Int] = '{1} + def b given QuoteContext: Expr[Int] = '{ ${ this.a } } - def d: Expr[Expr[Int]] = '{ '{1} } - def e: Expr[Expr[Int]] = '{ + def d given QuoteContext: Expr[Expr[Int]] = '{ '{1} } + def e given QuoteContext: Expr[Expr[Int]] = '{ '{${${this.d}}} } def foo[T](x: T): T = x - def f = '{ + def f given QuoteContext = '{ ${ foo[this.type](this).a } } @@ -24,5 +24,5 @@ class Foo { } object Foo { - def impl[T](x: Any): Expr[Unit] = '{} + def impl[T](x: Any) given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/pos/quoted-inline-quote.scala b/tests/pos/quoted-inline-quote.scala index 70212ca52582..90fc7710a39a 100644 --- a/tests/pos/quoted-inline-quote.scala +++ b/tests/pos/quoted-inline-quote.scala @@ -1,4 +1,7 @@ +import scala.quoted._ class Foo { - inline def foo(x: quoted.Expr[String]) = '{ println(${x}) } + inline def foo(x: Expr[String]) given QuoteContext = '{ println(${x}) } + + delegate for QuoteContext = ??? foo('{"abc"}) } \ No newline at end of file diff --git a/tests/run-macros/i4515/Macro_1.scala b/tests/run-macros/i4515/Macro_1.scala index b392bf410b57..aaeb2e48b8ad 100644 --- a/tests/run-macros/i4515/Macro_1.scala +++ b/tests/run-macros/i4515/Macro_1.scala @@ -1,5 +1,5 @@ - +import scala.quoted._ object Macro { inline def foo[X](x: X): Unit = ${fooImpl('x)} - def fooImpl[X: quoted.Type](x: quoted.Expr[X]): quoted.Expr[Unit] = '{} + def fooImpl[X: quoted.Type](x: Expr[X]) given QuoteContext: Expr[Unit] = '{} } diff --git a/tests/run-macros/i4734/Macro_1.scala b/tests/run-macros/i4734/Macro_1.scala index ffbdfe3da8de..ef845271e8bc 100644 --- a/tests/run-macros/i4734/Macro_1.scala +++ b/tests/run-macros/i4734/Macro_1.scala @@ -24,7 +24,7 @@ object Macros { } class UnrolledRange(start: Int, end: Int) { - def foreach(f: Int => Expr[Unit]): Expr[Unit] = { + def foreach(f: Int => Expr[Unit]) given QuoteContext: Expr[Unit] = { @tailrec def loop(i: Int, acc: Expr[Unit]): Expr[Unit] = if (i >= 0) loop(i - 1, '{ ${f(i)}; $acc }) else acc diff --git a/tests/run-macros/i4735/Macro_1.scala b/tests/run-macros/i4735/Macro_1.scala index 408cdfe7591a..e5142aa990b0 100644 --- a/tests/run-macros/i4735/Macro_1.scala +++ b/tests/run-macros/i4735/Macro_1.scala @@ -26,7 +26,7 @@ object Macro { } private class UnrolledRange(start: Int, end: Int) { - def foreach(f: Int => Expr[Unit]): Expr[Unit] = { + def foreach(f: Int => Expr[Unit]) given QuoteContext: Expr[Unit] = { @tailrec def loop(i: Int, acc: Expr[Unit]): Expr[Unit] = if (i >= 0) loop(i - 1, '{ ${f(i)}; $acc }) else acc diff --git a/tests/run-macros/i4803/Macro_1.scala b/tests/run-macros/i4803/Macro_1.scala index 9e1455107699..09025feae4f7 100644 --- a/tests/run-macros/i4803/Macro_1.scala +++ b/tests/run-macros/i4803/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object PowerMacro { - def powerCode(x: Expr[Double], n: Long): Expr[Double] = + def powerCode(x: Expr[Double], n: Long) given QuoteContext: Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${ powerCode('y, n / 2) } } else '{ $x * ${ powerCode(x, n - 1) } } diff --git a/tests/run-macros/i4803b/Macro_1.scala b/tests/run-macros/i4803b/Macro_1.scala index 48eab25d259b..e6d195a59004 100644 --- a/tests/run-macros/i4803b/Macro_1.scala +++ b/tests/run-macros/i4803b/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object PowerMacro { - def powerCode(x: Expr[Double], n: Long): Expr[Double] = + def powerCode(x: Expr[Double], n: Long) given QuoteContext: Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${ powerCode('y, n / 2) } } else '{ $x * ${ powerCode(x, n - 1) } } diff --git a/tests/run-macros/i4803c/Macro_1.scala b/tests/run-macros/i4803c/Macro_1.scala index 8070c3180721..0dd6ffbec477 100644 --- a/tests/run-macros/i4803c/Macro_1.scala +++ b/tests/run-macros/i4803c/Macro_1.scala @@ -1,7 +1,7 @@ import scala.quoted._ object PowerMacro { - def powerCode(x: Expr[Double], n: Long): Expr[Double] = + def powerCode(x: Expr[Double], n: Long) given QuoteContext: Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${powerCode('y, n / 2)} } else '{ $x * ${powerCode(x, n - 1)} } diff --git a/tests/run-macros/i4803f/Macro_1.scala b/tests/run-macros/i4803f/Macro_1.scala index 25aee2bf00c7..8678222002ca 100644 --- a/tests/run-macros/i4803f/Macro_1.scala +++ b/tests/run-macros/i4803f/Macro_1.scala @@ -1,12 +1,12 @@ import scala.quoted._ object PowerMacro { - def powerCode(x: Expr[Double], n: Long): Expr[Double] = + def powerCode(x: Expr[Double], n: Long) given QuoteContext: Expr[Double] = if (n == 0) '{1.0} else if (n % 2 == 0) '{ val y = $x * $x; ${powerCode('y, n / 2)} } else '{ $x * ${powerCode(x, n - 1)} } - def power2(x: Expr[Double]) = '{ + def power2(x: Expr[Double]) given QuoteContext = '{ inline def power(x: Double): Double = ${powerCode('x, 2)} power($x) } diff --git a/tests/run-macros/i4947f/Macro_1.scala b/tests/run-macros/i4947f/Macro_1.scala index acbf4f25f5a8..270a6f8f99a2 100644 --- a/tests/run-macros/i4947f/Macro_1.scala +++ b/tests/run-macros/i4947f/Macro_1.scala @@ -4,7 +4,7 @@ object Macros { def printStack(tag: String): Unit = { println(tag + ": "+ new Exception().getStackTrace().apply(1)) } - def assertImpl(expr: Expr[Boolean]) = '{ + def assertImpl(expr: Expr[Boolean]) given QuoteContext = '{ printStack("assertImpl") println($expr) } diff --git a/tests/run-macros/i6765-b.check b/tests/run-macros/i6765-b.check index 5b3a32df1825..2d03ff93827f 100644 --- a/tests/run-macros/i6765-b.check +++ b/tests/run-macros/i6765-b.check @@ -1,8 +1,8 @@ { - val x$1: java.lang.String = "One" - scala.Nil.::[java.lang.String](x$1) + val x$3: java.lang.String = "One" + scala.Nil.::[java.lang.String](x$3) } { - val x$1: java.lang.String = "One" - scala.Nil.::[java.lang.String](x$1) + val x$3: java.lang.String = "One" + scala.Nil.::[java.lang.String](x$3) } diff --git a/tests/run-macros/i6765.check b/tests/run-macros/i6765.check index 5b3a32df1825..2d03ff93827f 100644 --- a/tests/run-macros/i6765.check +++ b/tests/run-macros/i6765.check @@ -1,8 +1,8 @@ { - val x$1: java.lang.String = "One" - scala.Nil.::[java.lang.String](x$1) + val x$3: java.lang.String = "One" + scala.Nil.::[java.lang.String](x$3) } { - val x$1: java.lang.String = "One" - scala.Nil.::[java.lang.String](x$1) + val x$3: java.lang.String = "One" + scala.Nil.::[java.lang.String](x$3) } diff --git a/tests/run-macros/quote-and-splice/Macros_1.scala b/tests/run-macros/quote-and-splice/Macros_1.scala index f74d33359bf4..f2c91b2722c1 100644 --- a/tests/run-macros/quote-and-splice/Macros_1.scala +++ b/tests/run-macros/quote-and-splice/Macros_1.scala @@ -3,23 +3,23 @@ import scala.quoted._ object Macros { inline def macro1 = ${ macro1Impl } - def macro1Impl = '{3} + def macro1Impl given QuoteContext = '{3} inline def macro2(inline p: Boolean) = ${ macro2Impl(p) } - def macro2Impl(p: Boolean) = if (p) '{3} else '{4} + def macro2Impl(p: Boolean) given QuoteContext = if (p) '{3} else '{4} inline def macro3(n: Int) = ${ macro3Impl('n) } - def macro3Impl(p: Expr[Int]) = '{ 2 + $p } + def macro3Impl(p: Expr[Int]) given QuoteContext = '{ 2 + $p } inline def macro4(i: Int)(j: Int) = ${ macro4Impl('i)('j) } - def macro4Impl(i: Expr[Int])(j: Expr[Int]) = '{ $i + $j } + def macro4Impl(i: Expr[Int])(j: Expr[Int]) given QuoteContext = '{ $i + $j } inline def macro5(i: Int, j: Int) = ${ macro5Impl(j = 'j, i = 'i) } - def macro5Impl(i: Expr[Int], j: Expr[Int]) = '{ $i + $j } + def macro5Impl(i: Expr[Int], j: Expr[Int]) given QuoteContext = '{ $i + $j } inline def power(inline n: Int, x: Double) = ${ powerCode(n, 'x) } - def powerCode(n: Int, x: Expr[Double]): Expr[Double] = + def powerCode(n: Int, x: Expr[Double]) given QuoteContext: Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } diff --git a/tests/run-macros/quote-whitebox/Macro_1.scala b/tests/run-macros/quote-whitebox/Macro_1.scala index 11eb26bf60df..c86c63cbb2e6 100644 --- a/tests/run-macros/quote-whitebox/Macro_1.scala +++ b/tests/run-macros/quote-whitebox/Macro_1.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Macros { inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl(str) } - def defaultOfImpl(str: String): Expr[Any] = str match { + def defaultOfImpl(str: String) given QuoteContext: Expr[Any] = str match { case "int" => '{1} case "string" => '{"a"} } diff --git a/tests/run-with-compiler/i3876-b.scala b/tests/run-with-compiler/i3876-b.scala index 22eb62c3d3be..7f1e2884b6b4 100644 --- a/tests/run-with-compiler/i3876-b.scala +++ b/tests/run-with-compiler/i3876-b.scala @@ -3,9 +3,9 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val x: Expr[Int] = '{3} + def x given QuoteContext: Expr[Int] = '{3} - val f2: Expr[Int => Int] = '{ + def f2 given QuoteContext: Expr[Int => Int] = '{ def f(x: Int): Int = x + x f } diff --git a/tests/run-with-compiler/i3876-c.scala b/tests/run-with-compiler/i3876-c.scala index 7e9ab0baff5f..a28194a04d6d 100644 --- a/tests/run-with-compiler/i3876-c.scala +++ b/tests/run-with-compiler/i3876-c.scala @@ -3,9 +3,9 @@ object Test { def main(args: Array[String]): Unit = { implicit def toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val x: Expr[Int] = '{3} + def x given QuoteContext: Expr[Int] = '{3} - val f3: Expr[Int => Int] = '{ + def f3 given QuoteContext: Expr[Int => Int] = '{ val f: (x: Int) => Int = x => x + x f } diff --git a/tests/run-with-compiler/i3876-d.scala b/tests/run-with-compiler/i3876-d.scala index bcdbe8818abc..d61f09048bb6 100644 --- a/tests/run-with-compiler/i3876-d.scala +++ b/tests/run-with-compiler/i3876-d.scala @@ -3,9 +3,9 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val x: Expr[Int] = '{3} + def x given QuoteContext: Expr[Int] = '{3} - val f4: Expr[Int => Int] = '{ + def f4 given QuoteContext: Expr[Int => Int] = '{ inlineLambda } println(run(f4(x))) diff --git a/tests/run-with-compiler/i3876.scala b/tests/run-with-compiler/i3876.scala index a1c57e438f14..ed9b1e6c2b76 100644 --- a/tests/run-with-compiler/i3876.scala +++ b/tests/run-with-compiler/i3876.scala @@ -3,9 +3,9 @@ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val x: Expr[Int] = '{3} + def x given QuoteContext: Expr[Int] = '{3} - val f: Expr[Int => Int] = '{ (x: Int) => x + x } + def f given QuoteContext: Expr[Int => Int] = '{ (x: Int) => x + x } println(run(f(x))) println(withQuoteContext(f(x).show)) diff --git a/tests/run-with-compiler/i3946.scala b/tests/run-with-compiler/i3946.scala index eff2fa9a507b..d6d30aa3d4ef 100644 --- a/tests/run-with-compiler/i3946.scala +++ b/tests/run-with-compiler/i3946.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { def main(args: Array[String]): Unit = { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - val u: Expr[Unit] = '{} + def u given QuoteContext: Expr[Unit] = '{} println(withQuoteContext(u.show)) println(run(u)) } diff --git a/tests/run-with-compiler/i4044a.scala b/tests/run-with-compiler/i4044a.scala index 9486c20bdc68..bf64dc60c419 100644 --- a/tests/run-with-compiler/i4044a.scala +++ b/tests/run-with-compiler/i4044a.scala @@ -1,11 +1,11 @@ import scala.quoted._ class Foo { - def foo: 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 foo: Unit = withQuoteContext { val e: Expr[Int] = '{3} val q = '{ ${ '{ $e } } } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/i4044b.scala b/tests/run-with-compiler/i4044b.scala index 1c63e62f612d..4968327e3667 100644 --- a/tests/run-with-compiler/i4044b.scala +++ b/tests/run-with-compiler/i4044b.scala @@ -1,17 +1,17 @@ import scala.quoted._ sealed abstract class VarRef[T] { - def update(expr: Expr[T]): Expr[Unit] - def expr: Expr[T] + def update(expr: Expr[T]) given QuoteContext: Expr[Unit] + def expr given QuoteContext: Expr[T] } object VarRef { - def apply[T: Type, U: Type](init: Expr[T])(body: VarRef[T] => Expr[U]): Expr[U] = '{ + def apply[T: Type, U: Type](init: Expr[T])(body: VarRef[T] => Expr[U]) given QuoteContext: Expr[U] = '{ var x = $init ${body( new VarRef { - def update(e: Expr[T]): Expr[Unit] = '{ x = $e } - def expr: Expr[T] = 'x + def update(e: Expr[T]) given QuoteContext: Expr[Unit] = '{ x = $e } + def expr given QuoteContext: Expr[T] = 'x } )} } @@ -19,9 +19,9 @@ object VarRef { } 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 q = VarRef('{4})(varRef => '{ ${varRef.update('{3})}; ${varRef.expr} }) - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/i4044c.scala b/tests/run-with-compiler/i4044c.scala index 1777042fb563..8a8b5cc546e0 100644 --- a/tests/run-with-compiler/i4044c.scala +++ b/tests/run-with-compiler/i4044c.scala @@ -1,10 +1,10 @@ import scala.quoted._ class Foo { - def foo: 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 foo: Unit = withQuoteContext { val q = '{ ${ '{ ${ '{ 5 } } } } } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/i4044e.scala b/tests/run-with-compiler/i4044e.scala index 49d5994812e7..61cd5ce9b464 100644 --- a/tests/run-with-compiler/i4044e.scala +++ b/tests/run-with-compiler/i4044e.scala @@ -1,13 +1,13 @@ import scala.quoted._ class Foo { - def foo: 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 foo: Unit = withQuoteContext { val e: Expr[Int] = '{3} val f: Expr[Int] = '{5} val t: Type[Int] = '[Int] val q = '{ ${ '{ ($e + $f).asInstanceOf[$t] } } } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/i4044f.scala b/tests/run-with-compiler/i4044f.scala index 0cedf8187110..3a68edfb3f7a 100644 --- a/tests/run-with-compiler/i4044f.scala +++ b/tests/run-with-compiler/i4044f.scala @@ -1,8 +1,8 @@ import scala.quoted._ class Foo { - def foo: 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 foo: Unit = withQuoteContext { val e: Expr[Int] = '{3} val f: Expr[Int] = '{5} def foo(x: Expr[Int], y: Expr[Int]): Expr[Int] = '{ $x + $y } @@ -14,7 +14,7 @@ class Foo { foo('{e1 + $u}, '{f1}) } } - println(withQuoteContext(q.show)) + println(q.show) } } diff --git a/tests/run-with-compiler/i5144b.scala b/tests/run-with-compiler/i5144b.scala index 34ffb2a067f1..51cdcf2c210b 100644 --- a/tests/run-with-compiler/i5144b.scala +++ b/tests/run-with-compiler/i5144b.scala @@ -2,9 +2,9 @@ import scala.quoted._ object Test { implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) - def eval1(ff: Expr[Int => Int]): Expr[Int] = ff('{42}) + def eval1(ff: Expr[Int => Int]) given QuoteContext: Expr[Int] = ff('{42}) - def peval1(): Expr[Unit] = '{ + def peval1() given QuoteContext: Expr[Unit] = '{ def f(x: Int): Int = ${eval1('f)} } diff --git a/tests/run-with-compiler/quote-compile-constants.check b/tests/run-with-compiler/quote-compile-constants.check new file mode 100644 index 000000000000..5f2e2d87c193 --- /dev/null +++ b/tests/run-with-compiler/quote-compile-constants.check @@ -0,0 +1,17 @@ +Literal(Constant(null)) +Literal(Constant(true)) +Literal(Constant(a)) +Literal(Constant( +)) +Literal(Constant(")) +Literal(Constant(')) +Literal(Constant(\)) +Literal(Constant(1)) +Literal(Constant(2)) +Literal(Constant(3)) +Literal(Constant(4.0)) +Literal(Constant(5.0)) +Literal(Constant(xyz)) +Literal(Constant(())) +Literal(Constant(())) +Literal(Constant(())) diff --git a/tests/run-with-compiler/quote-compile-constants.scala b/tests/run-with-compiler/quote-compile-constants.scala new file mode 100644 index 000000000000..e6411b6e23bb --- /dev/null +++ b/tests/run-with-compiler/quote-compile-constants.scala @@ -0,0 +1,31 @@ +import scala.quoted._ + +object Test { + + implicit val toolbox: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader) + + def main(args: Array[String]): Unit = withQuoteContext { + val qctx = the[QuoteContext] + def check[T](expr: Expr[T]): Unit = { + import qctx.tasty._ + println(expr.unseal) + } + + check('{null}) + check('{true}) + check('{ 'a' }) + check('{ '\n' }) + check('{ '"' }) + check('{ '\'' }) + check('{ '\\' }) + check('{1}) + check('{ { { 2 } } }) + check('{3L}) + check('{4.0f}) + check('{5.0d}) + check('{"xyz"}) + check('{}) + check('{()}) + check('{{()}}) + } +} diff --git a/tests/run/quote-simple-hole.scala b/tests/run-with-compiler/quote-simple-hole.scala similarity index 59% rename from tests/run/quote-simple-hole.scala rename to tests/run-with-compiler/quote-simple-hole.scala index 5bfcf0ac45cd..f98c7496b69c 100644 --- a/tests/run/quote-simple-hole.scala +++ b/tests/run-with-compiler/quote-simple-hole.scala @@ -1,5 +1,9 @@ +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 { val x = '{0} val y = '{$x} val z = '{${'{$y}}} diff --git a/tests/run-with-compiler/quote-unrolled-foreach.scala b/tests/run-with-compiler/quote-unrolled-foreach.scala index 427275730c5b..e9d46d11340b 100644 --- a/tests/run-with-compiler/quote-unrolled-foreach.scala +++ b/tests/run-with-compiler/quote-unrolled-foreach.scala @@ -43,7 +43,7 @@ object Test { '{} } - def foreach1(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]): Expr[Unit] = '{ + def foreach1(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]) given QuoteContext: Expr[Unit] = '{ val size = ($arrRef).length var i = 0 while (i < size) { @@ -53,7 +53,7 @@ object Test { } } - def foreach1Tpe1[T](arrRef: Expr[Array[T]], f: Expr[T => Unit])(implicit t: Type[T]): Expr[Unit] = '{ + def foreach1Tpe1[T](arrRef: Expr[Array[T]], f: Expr[T => Unit])(implicit t: Type[T], qxtx: QuoteContext): Expr[Unit] = '{ val size = ($arrRef).length var i = 0 while (i < size) { @@ -63,7 +63,7 @@ object Test { } } - def foreach1Tpe2[T: Type](arrRef: Expr[Array[T]], f: Expr[T => Unit]): Expr[Unit] = '{ + def foreach1Tpe2[T: Type](arrRef: Expr[Array[T]], f: Expr[T => Unit]) given QuoteContext: Expr[Unit] = '{ val size = ($arrRef).length var i = 0 while (i < size) { @@ -83,7 +83,7 @@ object Test { } } - def foreach3(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]): Expr[Unit] = '{ + def foreach3(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]) given QuoteContext: Expr[Unit] = '{ val size = ($arrRef).length var i = 0 if (size % 3 != 0) throw new Exception("...")// for simplicity of the implementation @@ -95,7 +95,7 @@ object Test { } } - def foreach3_2(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]): Expr[Unit] = '{ + def foreach3_2(arrRef: Expr[Array[Int]], f: Expr[Int => Unit]) given QuoteContext: Expr[Unit] = '{ val size = ($arrRef).length var i = 0 if (size % 3 != 0) throw new Exception("...")// for simplicity of the implementation @@ -125,7 +125,7 @@ object Test { } } - def foreachInRange(start: Int, end: Int)(f: Int => Expr[Unit]): Expr[Unit] = { + def foreachInRange(start: Int, end: Int)(f: Int => Expr[Unit]) given QuoteContext: Expr[Unit] = { @tailrec def unroll(i: Int, acc: Expr[Unit]): Expr[Unit] = if (i < end) unroll(i + 1, '{ $acc; ${f(i)} }) else acc if (start < end) unroll(start + 1, f(start)) else '{} diff --git a/tests/run-with-compiler/quote-var.scala b/tests/run-with-compiler/quote-var.scala index 46b90e8306f8..d40101a71ba5 100644 --- a/tests/run-with-compiler/quote-var.scala +++ b/tests/run-with-compiler/quote-var.scala @@ -3,18 +3,18 @@ import scala.quoted._ object Test { sealed trait Var { - def get: Expr[String] - def update(x: Expr[String]): Expr[Unit] + def get given QuoteContext: Expr[String] + def update(x: Expr[String]) given QuoteContext: Expr[Unit] } object Var { - def apply(init: Expr[String])(body: Var => Expr[String]): Expr[String] = '{ + def apply(init: Expr[String])(body: Var => Expr[String]) given QuoteContext: Expr[String] = '{ var x = $init ${ body( new Var { - def get: Expr[String] = 'x - def update(e: Expr[String]): Expr[Unit] = '{ x = $e } + def get given QuoteContext: Expr[String] = 'x + def update(e: Expr[String]) given QuoteContext: Expr[Unit] = '{ x = $e } } ) } @@ -22,7 +22,7 @@ object Test { } - def test1(): Expr[String] = Var('{"abc"}) { x => + def test1() given QuoteContext: Expr[String] = Var('{"abc"}) { x => '{ ${ x.update('{"xyz"}) } ${ x.get } diff --git a/tests/run-with-compiler/shonan-hmm-simple.scala b/tests/run-with-compiler/shonan-hmm-simple.scala index 6cfc6ea421ed..0ab94d7038c1 100644 --- a/tests/run-with-compiler/shonan-hmm-simple.scala +++ b/tests/run-with-compiler/shonan-hmm-simple.scala @@ -17,7 +17,7 @@ class RingInt extends Ring[Int] { val mul = (x, y) => x * y } -class RingIntExpr extends Ring[Expr[Int]] { +class RingIntExpr given QuoteContext extends Ring[Expr[Int]] { val zero = '{0} val one = '{1} val add = (x, y) => '{$x + $y} @@ -150,8 +150,8 @@ object Test { println(run(resCode1)) println() - val blasExprIntExpr = new Blas1(new RingIntExpr, new ExprVecOps) - val resCode2: Expr[(Array[Int], Array[Int]) => Int] = '{ + def blasExprIntExpr given QuoteContext = new Blas1(new RingIntExpr, new ExprVecOps) + def resCode2 given QuoteContext: Expr[(Array[Int], Array[Int]) => Int] = '{ (arr1, arr2) => if (arr1.length != arr2.length) throw new Exception("...") ${ diff --git a/tests/run-with-compiler/shonan-hmm/MVmult.scala b/tests/run-with-compiler/shonan-hmm/MVmult.scala index eb08a5f846b8..defa4b977994 100644 --- a/tests/run-with-compiler/shonan-hmm/MVmult.scala +++ b/tests/run-with-compiler/shonan-hmm/MVmult.scala @@ -31,14 +31,14 @@ object MVmult { val a_ = Vec('n, (i: Expr[Int]) => Vec('m, (j: Expr[Int]) => '{ a($i)($j) } )) val v_ = Vec('m, (i: Expr[Int]) => '{v($i)}) - val MV = new MVmult[Expr[Int], Expr[Int], Expr[Unit]](RingIntExpr, new VecRDyn) + val MV = new MVmult[Expr[Int], Expr[Int], Expr[Unit]](new RingIntExpr, new VecRDyn) MV.mvmult(vout_, a_, v_) } } } def mvmult_mc(n: Int, m: Int) given QuoteContext: Expr[(Array[Int], Array[Array[Int]], Array[Int]) => Unit] = { - val MV = new MVmult[Int, Expr[Int], Expr[Unit]](RingIntExpr, new VecRStaDim(RingIntExpr)) + val MV = new MVmult[Int, Expr[Int], Expr[Unit]](new RingIntExpr, new VecRStaDim(new RingIntExpr)) '{ (vout, a, v) => { if (${n} != vout.length) throw new IndexOutOfBoundsException(${n.toString}) diff --git a/tests/run-with-compiler/shonan-hmm/Ring.scala b/tests/run-with-compiler/shonan-hmm/Ring.scala index 53447fe7ad13..2943127f4e16 100644 --- a/tests/run-with-compiler/shonan-hmm/Ring.scala +++ b/tests/run-with-compiler/shonan-hmm/Ring.scala @@ -24,7 +24,7 @@ object RingInt extends Ring[Int] { override def toString(): String = "RingInt" } -object RingIntExpr extends Ring[Expr[Int]] { +class RingIntExpr given QuoteContext extends Ring[Expr[Int]] { val zero = '{0} val one = '{1} val add = (x, y) => '{$x + $y} @@ -66,7 +66,7 @@ case class RingPV[U: Liftable](staRing: Ring[U], dynRing: Ring[Expr[U]]) given Q } } -class RingIntPExpr given QuoteContext extends RingPV(RingInt, RingIntExpr) +class RingIntPExpr given QuoteContext extends RingPV(RingInt, new RingIntExpr) class RingIntOPExpr given QuoteContext extends RingIntPExpr { override def add = (x: PV[Int], y: PV[Int]) => (x, y) match { diff --git a/tests/run-with-compiler/shonan-hmm/Test.scala b/tests/run-with-compiler/shonan-hmm/Test.scala index 2dbe6cc5d488..fcff0cf0e73e 100644 --- a/tests/run-with-compiler/shonan-hmm/Test.scala +++ b/tests/run-with-compiler/shonan-hmm/Test.scala @@ -16,7 +16,7 @@ object Test { } { - val intExprComplex = new RingComplex(RingIntExpr) + val intExprComplex = new RingComplex(new RingIntExpr) import intExprComplex._ val res = Complex('{1}, '{2}) * Complex('{4}, '{2}) diff --git a/tests/run-with-compiler/shonan-hmm/UnrolledExpr.scala b/tests/run-with-compiler/shonan-hmm/UnrolledExpr.scala index 56ab8a676740..2cd929fa8914 100644 --- a/tests/run-with-compiler/shonan-hmm/UnrolledExpr.scala +++ b/tests/run-with-compiler/shonan-hmm/UnrolledExpr.scala @@ -8,7 +8,7 @@ object UnrolledExpr { } // TODO support blocks in the compiler to avoid creating trees of blocks? - def block[T: Type](stats: Iterable[Expr[_]], expr: Expr[T]): Expr[T] = { + def block[T: Type](stats: Iterable[Expr[_]], expr: Expr[T]) given QuoteContext: Expr[T] = { def rec(stats: List[Expr[_]]): Expr[T] = stats match { case x :: xs => '{ $x; ${rec(xs)} } case Nil => expr @@ -21,10 +21,10 @@ object UnrolledExpr { class UnrolledExpr[T: Liftable, It <: Iterable[T]](xs: It) { import UnrolledExpr._ - def foreach[U](f: T => Expr[U]): Expr[Unit] = block(xs.map(f), '{}) + def foreach[U](f: T => Expr[U]) given QuoteContext: Expr[Unit] = block(xs.map(f), '{}) - def withFilter(f: T => Boolean): UnrolledExpr[T, Iterable[T]] = new UnrolledExpr(xs.filter(f)) + def withFilter(f: T => Boolean) given QuoteContext: UnrolledExpr[T, Iterable[T]] = new UnrolledExpr(xs.filter(f)) - def foldLeft[U](acc: Expr[U])(f: (Expr[U], T) => Expr[U]): Expr[U] = + def foldLeft[U](acc: Expr[U])(f: (Expr[U], T) => Expr[U]) given QuoteContext: Expr[U] = xs.foldLeft(acc)((acc, x) => f(acc, x)) } diff --git a/tests/run-with-compiler/shonan-hmm/VecROp.scala b/tests/run-with-compiler/shonan-hmm/VecROp.scala index 584e3f202e26..2996ba754b0d 100644 --- a/tests/run-with-compiler/shonan-hmm/VecROp.scala +++ b/tests/run-with-compiler/shonan-hmm/VecROp.scala @@ -17,7 +17,7 @@ class StaticVecR[T](r: Ring[T]) extends VecSta with VecROp[Int, T, Unit] { override def toString(): String = s"StaticVecR($r)" } -class VecRDyn[T: Type] extends VecDyn with VecROp[Expr[Int], Expr[T], Expr[Unit]] { +class VecRDyn[T: Type] given QuoteContext extends VecDyn with VecROp[Expr[Int], Expr[T], Expr[Unit]] { def reduce: ((Expr[T], Expr[T]) => Expr[T], Expr[T], Vec[Expr[Int], Expr[T]]) => Expr[T] = { (plus, zero, vec) => '{ var sum = $zero @@ -32,7 +32,7 @@ class VecRDyn[T: Type] extends VecDyn with VecROp[Expr[Int], Expr[T], Expr[Unit] override def toString(): String = s"VecRDyn" } -class VecRStaDim[T: Type](r: Ring[T]) extends VecROp[Int, T, Expr[Unit]] { +class VecRStaDim[T: Type](r: Ring[T]) given QuoteContext extends VecROp[Int, T, Expr[Unit]] { val M = new StaticVecR[T](r) def reduce: ((T, T) => T, T, Vec[Int, T]) => T = M.reduce val seq: (Expr[Unit], Expr[Unit]) => Expr[Unit] = (e1, e2) => '{ $e1; $e2 } @@ -46,7 +46,7 @@ class VecRStaDim[T: Type](r: Ring[T]) extends VecROp[Int, T, Expr[Unit]] { override def toString(): String = s"VecRStaDim($r)" } -class VecRStaDyn[T : Type : Liftable](r: Ring[PV[T]]) given QuoteContext extends VecROp[PV[Int], PV[T], Expr[Unit]] { +class VecRStaDyn[T : Type : Liftable](r: Ring[PV[T]]) given QuoteContext extends VecROp[PV[Int], PV[T], Expr[Unit]] { val VSta: VecROp[Int, PV[T], Expr[Unit]] = new VecRStaDim(r) val VDyn = new VecRDyn val dyn = Dyns.dyn[T] diff --git a/tests/run-with-compiler/shonan-hmm/Vmults.scala b/tests/run-with-compiler/shonan-hmm/Vmults.scala index a1709b5edf3e..86a8bec0b548 100644 --- a/tests/run-with-compiler/shonan-hmm/Vmults.scala +++ b/tests/run-with-compiler/shonan-hmm/Vmults.scala @@ -27,7 +27,7 @@ object Vmults { val v1_ = Vec ('n, i => Complex.of_complex_expr('{v1($i)})) val v2_ = Vec ('n, i => Complex.of_complex_expr('{v2($i)})) - val V = new Vmult[Expr[Int], Complex[Expr[Int]], Expr[Unit]](RingComplex(RingIntExpr), new VecDyn) + val V = new Vmult[Expr[Int], Complex[Expr[Int]], Expr[Unit]](RingComplex(new RingIntExpr), new VecDyn) V.vmult(vout_, v1_, v2_) } } diff --git a/tests/run-with-compiler/staged-tuples/StagedTuple.scala b/tests/run-with-compiler/staged-tuples/StagedTuple.scala index 3bfd65528d4a..4085e745cfa6 100644 --- a/tests/run-with-compiler/staged-tuples/StagedTuple.scala +++ b/tests/run-with-compiler/staged-tuples/StagedTuple.scala @@ -34,7 +34,7 @@ object StagedTuple { } } - def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int]): Expr[T] = { + def fromArrayStaged[T <: Tuple : Type](xs: Expr[Array[Object]], size: Option[Int]) given QuoteContext: Expr[T] = { if (!specialize) '{dynamicFromArray[T]($xs)} else xs.bind { xs => val tup: Expr[Any] = size match { @@ -78,7 +78,7 @@ object StagedTuple { res.as[Res] } - def headStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int]): Expr[Head[Tup]] = { + def headStaged[Tup <: NonEmptyTuple : Type](tup: Expr[Tup], size: Option[Int]) given QuoteContext: Expr[Head[Tup]] = { if (!specialize) '{dynamicApply($tup, 0)} else { val resVal = size match { @@ -256,9 +256,9 @@ object StagedTuple { private implicit class ExprOps[U: Type](expr: Expr[U]) { - def as[T: Type]: Expr[T] = '{ $expr.asInstanceOf[T] } + def as[T: Type] given QuoteContext: Expr[T] = '{ $expr.asInstanceOf[T] } - def bind[T: Type](in: Expr[U] => Expr[T]): Expr[T] = '{ + def bind[T: Type](in: Expr[U] => Expr[T]) given QuoteContext: Expr[T] = '{ val t: U = $expr ${in('t)} } 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 befb0542a3a1..c998ea1bc364 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 @@ -51,7 +51,7 @@ object Macros { } } - def powerCode(n: Int, x: Expr[Double]): Expr[Double] = + def powerCode(n: Int, x: Expr[Double]) given QuoteContext: Expr[Double] = if (n == 0) '{1.0} else if (n == 1) x else if (n % 2 == 0) '{ { val y = $x * $x; ${powerCode(n / 2, 'y)} } } diff --git a/tests/run/quote-compile-constants.check b/tests/run/quote-compile-constants.check deleted file mode 100644 index 7128f747bf3a..000000000000 --- a/tests/run/quote-compile-constants.check +++ /dev/null @@ -1,15 +0,0 @@ -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr -class scala.internal.quoted.LiftedExpr diff --git a/tests/run/quote-compile-constants.scala b/tests/run/quote-compile-constants.scala deleted file mode 100644 index 9fd8a478f82c..000000000000 --- a/tests/run/quote-compile-constants.scala +++ /dev/null @@ -1,21 +0,0 @@ -import scala.quoted._ - -object Test { - def main(args: Array[String]): Unit = { - println(('{true}).getClass) - println(('{ 'a' }).getClass) - println(('{ '\n' }).getClass) - println(('{ '"' }).getClass) - println(('{ '\'' }).getClass) - println(('{ '\\' }).getClass) - println(('{1}).getClass) - println(('{ { { 2 } } }).getClass) - println(('{3L}).getClass) - println(('{4.0f}).getClass) - println(('{5.0d}).getClass) - println(('{"xyz"}).getClass) - println(('{}).getClass) - println(('{()}).getClass) - println(('{{()}}).getClass) - } -}