diff --git a/community-build/src/scala/dotty/communitybuild/FieldsImpl.scala b/community-build/src/scala/dotty/communitybuild/FieldsImpl.scala index e47d8debd6e4..4c045968ee97 100644 --- a/community-build/src/scala/dotty/communitybuild/FieldsImpl.scala +++ b/community-build/src/scala/dotty/communitybuild/FieldsImpl.scala @@ -11,7 +11,7 @@ object FieldsImpl: val retType = TypeTree.of[T].tpe def isProjectField(s: Symbol) = s.isValDef && s.tree.asInstanceOf[ValDef].tpt.tpe <:< retType - val projectsTree = Term.of(from) + val projectsTree = from.asTerm val symbols = TypeTree.of[V].symbol.fields.filter(isProjectField) val selects = symbols.map(Select(projectsTree, _).asExprOf[T]) '{ println(${Expr(retType.show)}); ${Varargs(selects)} } diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index f26cb10d47a6..e551296d1f01 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -48,17 +48,17 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler extension [T](self: scala.quoted.Expr[T]): def show: String = - reflect.Printer.TreeCode.show(reflect.Term.of(self)) + reflect.Printer.TreeCode.show(reflect.asTerm(self)) def matches(that: scala.quoted.Expr[Any]): Boolean = - treeMatch(reflect.Term.of(self), reflect.Term.of(that)).nonEmpty + treeMatch(reflect.asTerm(self), reflect.asTerm(that)).nonEmpty end extension extension [X](self: scala.quoted.Expr[Any]): /** Checks is the `quoted.Expr[?]` is valid expression of type `X` */ def isExprOf(using scala.quoted.Type[X]): Boolean = - reflect.TypeReprMethods.<:<(reflect.Term.of(self).tpe)(reflect.TypeRepr.of[X]) + reflect.TypeReprMethods.<:<(reflect.asTerm(self).tpe)(reflect.TypeRepr.of[X]) /** Convert this to an `quoted.Expr[X]` if this expression is a valid expression of type `X` or throws */ def asExprOf(using scala.quoted.Type[X]): scala.quoted.Expr[X] = { @@ -67,7 +67,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler else throw Exception( s"""Expr cast exception: ${self.show} - |of type: ${reflect.Printer.TypeReprCode.show(reflect.Term.of(self).tpe)} + |of type: ${reflect.Printer.TypeReprCode.show(reflect.asTerm(self).tpe)} |did not conform to type: ${reflect.Printer.TypeReprCode.show(reflect.TypeRepr.of[X])} |""".stripMargin ) @@ -76,11 +76,16 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object reflect extends reflectModule: + extension (expr: Expr[Any]): + def asTerm: Term = + val exprImpl = expr.asInstanceOf[ExprImpl] + exprImpl.checkScopeId(QuotesImpl.this.hashCode) + exprImpl.tree + end extension + type Tree = tpd.Tree - object Tree extends TreeModule: - def of(expr: Expr[Any]): Tree = Term.of(expr) - end Tree + object Tree extends TreeModule given TreeMethods: TreeMethods with extension (self: Tree): @@ -340,11 +345,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler end TermTypeTest object Term extends TermModule: - def of(expr: Expr[Any]): Term = - val exprImpl = expr.asInstanceOf[ExprImpl] - exprImpl.checkScopeId(QuotesImpl.this.hashCode) - exprImpl.tree - def betaReduce(tree: Term): Option[Term] = tree match case app @ tpd.Apply(tpd.Select(fn, nme.apply), args) if dotc.core.Symbols.defn.isFunctionType(fn.tpe) => @@ -2588,7 +2588,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler dotc.report.error(msg, Position.ofMacroExpansion) def error(msg: String, expr: Expr[Any]): Unit = - dotc.report.error(msg, Term.of(expr).pos) + dotc.report.error(msg, asTerm(expr).pos) def error(msg: String, pos: Position): Unit = dotc.report.error(msg, pos) @@ -2609,7 +2609,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler dotc.report.warning(msg, Position.ofMacroExpansion) def warning(msg: String, expr: Expr[Any]): Unit = - dotc.report.warning(msg, Term.of(expr).pos) + dotc.report.warning(msg, asTerm(expr).pos) def warning(msg: String, pos: Position): Unit = dotc.report.warning(msg, pos) @@ -2716,8 +2716,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object ExprMatch extends ExprMatchModule: def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutinee: scala.quoted.Expr[Any])(using pattern: scala.quoted.Expr[Any]): Option[Tup] = - val scrutineeTree = reflect.Term.of(scrutinee) - val patternTree = reflect.Term.of(pattern) + val scrutineeTree = reflect.asTerm(scrutinee) + val patternTree = reflect.asTerm(pattern) treeMatch(scrutineeTree, patternTree).asInstanceOf[Option[Tup]] end ExprMatch diff --git a/docs/docs/reference/metaprogramming/tasty-reflect.md b/docs/docs/reference/metaprogramming/tasty-reflect.md index 3c351585bcba..666b68f9696f 100644 --- a/docs/docs/reference/metaprogramming/tasty-reflect.md +++ b/docs/docs/reference/metaprogramming/tasty-reflect.md @@ -42,7 +42,7 @@ trees. For example the `Literal(_)` extractor used below. ```scala def natConstImpl(x: Expr[Int])(using Quotes): Expr[Int] = { import quotes.reflect._ - val xTree: Term = Term.of(x) + val xTree: Term = x.asTerm xTree match { case Inlined(_, _, Literal(Constant(n: Int))) => if (n <= 0) { diff --git a/library/src-bootstrapped/scala/quoted/Expr.scala b/library/src-bootstrapped/scala/quoted/Expr.scala index 263c0de50330..a48e3fd0b63c 100644 --- a/library/src-bootstrapped/scala/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/quoted/Expr.scala @@ -19,7 +19,7 @@ object Expr { */ def betaReduce[T](expr: Expr[T])(using Quotes): Expr[T] = import quotes.reflect._ - Term.betaReduce(Term.of(expr)) match + Term.betaReduce(expr.asTerm) match case Some(expr1) => expr1.asExpr.asInstanceOf[Expr[T]] case _ => expr @@ -29,7 +29,7 @@ object Expr { */ def block[T](statements: List[Expr[Any]], expr: Expr[T])(using Quotes): Expr[T] = { import quotes.reflect._ - Block(statements.map(Term.of), Term.of(expr)).asExpr.asInstanceOf[Expr[T]] + Block(statements.map(asTerm), expr.asTerm).asExpr.asInstanceOf[Expr[T]] } /** Creates an expression that will construct the value `x` */ diff --git a/library/src-bootstrapped/scala/quoted/FromExpr.scala b/library/src-bootstrapped/scala/quoted/FromExpr.scala index 5d8bd49e2ff5..6f57c542af50 100644 --- a/library/src-bootstrapped/scala/quoted/FromExpr.scala +++ b/library/src-bootstrapped/scala/quoted/FromExpr.scala @@ -90,7 +90,7 @@ object FromExpr { case Inlined(_, Nil, e) => rec(e) case _ => None } - rec(Term.of(expr)) + rec(expr.asTerm) } /** Default implementation of `FromExpr[Option]` diff --git a/library/src/scala/quoted/Const.scala b/library/src/scala/quoted/Const.scala index a22370ddbec9..2cc40d4a9de6 100644 --- a/library/src/scala/quoted/Const.scala +++ b/library/src/scala/quoted/Const.scala @@ -34,7 +34,7 @@ object Const { case Inlined(_, Nil, e) => rec(e) case _ => None } - rec(Term.of(expr)) + rec(expr.asTerm) } } diff --git a/library/src/scala/quoted/ExprMap.scala b/library/src/scala/quoted/ExprMap.scala index bc4e167fb431..9c484c7bc0cb 100644 --- a/library/src/scala/quoted/ExprMap.scala +++ b/library/src/scala/quoted/ExprMap.scala @@ -100,13 +100,13 @@ trait ExprMap: transformTermChildren(tree, tpe)(owner) case _ if tree.isExpr => // WARNING: Never do a cast like this in user code (accepable within the stdlib). - // In theory we should use `tree.asExpr match { case '{ $expr: t } => Term.of(transform(expr)) }` + // In theory we should use `tree.asExpr match { case '{ $expr: t } => transform(expr).asTerm }` // This is to avoid conflicts when re-boostrapping the library. type X val expr = tree.asExpr.asInstanceOf[Expr[X]] val t = tpe.asType.asInstanceOf[Type[X]] val transformedExpr = transform(expr)(using t) - Term.of(transformedExpr) + transformedExpr.asTerm case _ => transformTermChildren(tree, tpe)(owner) @@ -145,7 +145,7 @@ trait ExprMap: trees.mapConserve(x => transformTypeCaseDef(x)(owner)) } - new MapChildren().transformTermChildren(Term.of(e), TypeRepr.of[T])(Symbol.spliceOwner).asExprOf[T] + new MapChildren().transformTermChildren(e.asTerm, TypeRepr.of[T])(Symbol.spliceOwner).asExprOf[T] } end ExprMap diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 6828d4a067f4..503cbb37ce69 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -76,7 +76,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => * import scala.quoted._ * def f(expr: Expr[Int])(using Quotes) = * import quotes.reflect._ - * val tree: Tree = Term.of(expr) + * val ast: Term = expr.asTerm * ... * ``` * @@ -201,11 +201,14 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => */ trait reflectModule { self: reflect.type => + /** Returns the `Term` representation this expression */ + extension (expr: Expr[Any]) + def asTerm: Term + /////////////// // TREES // /////////////// - /** Tree representing code written in the source */ type Tree <: AnyRef @@ -215,7 +218,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** Methods of the module object `val Tree` */ trait TreeModule { this: Tree.type => /** Returns the Term representation this expression */ - def of(expr: Expr[Any]): Tree + @deprecated("Use `expr.asTerm` instead (must `import quotes.reflect._`). This will be removed in 3.0.0-RC1", "3.0.0-M3") + def of(expr: Expr[Any]): Tree = expr.asTerm } /** Makes extension methods on `Tree` available without any imports */ @@ -509,7 +513,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => trait TermModule { this: Term.type => /** Returns the Term representation this expression */ - def of(expr: Expr[Any]): Term + @deprecated("Use `expr.asTerm` instead (must `import quotes.reflect._`). This will be removed in 3.0.0-RC1", "3.0.0-M3") + def of(expr: Expr[Any]): Term = expr.asTerm /** Returns a term that is functionally equivalent to `t`, * however if `t` is of the form `((y1, ..., yn) => e2)(e1, ..., en)` diff --git a/library/src/scala/quoted/Varargs.scala b/library/src/scala/quoted/Varargs.scala index 5899443c3aeb..62c80b18b959 100644 --- a/library/src/scala/quoted/Varargs.scala +++ b/library/src/scala/quoted/Varargs.scala @@ -21,7 +21,7 @@ object Varargs { */ def apply[T](xs: Seq[Expr[T]])(using Type[T])(using Quotes): Expr[Seq[T]] = { import quotes.reflect._ - Repeated(xs.map(Term.of).toList, TypeTree.of[T]).asExpr.asInstanceOf[Expr[Seq[T]]] + Repeated(xs.map(_.asTerm).toList, TypeTree.of[T]).asExpr.asInstanceOf[Expr[Seq[T]]] } /** Matches a literal sequence of expressions and return a sequence of expressions. @@ -44,7 +44,7 @@ object Varargs { case Inlined(_, Nil, e) => rec(e) case _ => None } - rec(Term.of(expr)) + rec(expr.asTerm) } } diff --git a/tests/neg-macros/i6432/Macro_1.scala b/tests/neg-macros/i6432/Macro_1.scala index dfb26889fd44..f42bc0121403 100644 --- a/tests/neg-macros/i6432/Macro_1.scala +++ b/tests/neg-macros/i6432/Macro_1.scala @@ -10,7 +10,7 @@ object Macro { sc match { case '{ StringContext(${Varargs(parts)}: _*) } => for (part @ Const(s) <- parts) - report.error(s, Term.of(part).pos) + report.error(s, part.asTerm.pos) } '{} } diff --git a/tests/neg-macros/i6432b/Macro_1.scala b/tests/neg-macros/i6432b/Macro_1.scala index dfb26889fd44..f42bc0121403 100644 --- a/tests/neg-macros/i6432b/Macro_1.scala +++ b/tests/neg-macros/i6432b/Macro_1.scala @@ -10,7 +10,7 @@ object Macro { sc match { case '{ StringContext(${Varargs(parts)}: _*) } => for (part @ Const(s) <- parts) - report.error(s, Term.of(part).pos) + report.error(s, part.asTerm.pos) } '{} } diff --git a/tests/neg-macros/i6976/Macro_1.scala b/tests/neg-macros/i6976/Macro_1.scala index 18ecfb72a694..c12f9f12fff8 100644 --- a/tests/neg-macros/i6976/Macro_1.scala +++ b/tests/neg-macros/i6976/Macro_1.scala @@ -7,6 +7,6 @@ object macros { def mcrImpl(body: Expr[Any])(using ctx: Quotes) : Expr[Any] = { import ctx.reflect._ - Term.of(body) match { case Block(_, _) => '{2} } + body.asTerm match { case Block(_, _) => '{2} } } } diff --git a/tests/neg-macros/i7698.scala b/tests/neg-macros/i7698.scala index 411b52b51a74..b6d3c8817871 100644 --- a/tests/neg-macros/i7698.scala +++ b/tests/neg-macros/i7698.scala @@ -6,7 +6,7 @@ trait Show[T] { def showInterpolatorImpl(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes): Expr[String] = import quotes.reflect._ - Term.of(argsExpr) match + argsExpr.asTerm match case '{ $arg: $t } => // error case '[ Int ] => // error ??? diff --git a/tests/neg-macros/i9801/Macro_1.scala b/tests/neg-macros/i9801/Macro_1.scala index c9b93838b91a..1d544c66e64f 100644 --- a/tests/neg-macros/i9801/Macro_1.scala +++ b/tests/neg-macros/i9801/Macro_1.scala @@ -16,6 +16,6 @@ def impl(prog: Expr[Double])(using Quotes) : Expr[Double] = triggerStackOverflow(0) } catch { case e => - quotes.reflect.report.error(e.getMessage, Term.of(prog).pos) + quotes.reflect.report.error(e.getMessage, prog.asTerm.pos) '{ 42.0 } } diff --git a/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala b/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala index 2351dae9c324..4eab8e37bfb2 100644 --- a/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-assert-1/quoted_1.scala @@ -15,7 +15,7 @@ object Asserts { def impl(cond: Expr[Boolean])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(cond) + val tree = cond.asTerm def isOps(tpe: TypeRepr): Boolean = tpe match { case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts diff --git a/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala b/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala index a069bb363c48..ecf291b973da 100644 --- a/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-assert-2/quoted_1.scala @@ -15,7 +15,7 @@ object Asserts { def impl(cond: Expr[Boolean])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(cond) + val tree = cond.asTerm def isOps(tpe: TypeRepr): Boolean = tpe match { case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts diff --git a/tests/neg-macros/tasty-macro-error/quoted_1.scala b/tests/neg-macros/tasty-macro-error/quoted_1.scala index 444500928364..74478c7bd5a6 100644 --- a/tests/neg-macros/tasty-macro-error/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-error/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { def impl(x: Expr[Any])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - report.error("here is the the argument is " + Term.of(x).underlyingArgument.show, Term.of(x).underlyingArgument.pos) + report.error("here is the the argument is " + x.asTerm.underlyingArgument.show, x.asTerm.underlyingArgument.pos) '{} } diff --git a/tests/neg-macros/tasty-macro-positions/quoted_1.scala b/tests/neg-macros/tasty-macro-positions/quoted_1.scala index d63043f29a7c..01917a3f1011 100644 --- a/tests/neg-macros/tasty-macro-positions/quoted_1.scala +++ b/tests/neg-macros/tasty-macro-positions/quoted_1.scala @@ -6,9 +6,9 @@ object Macros { def impl(x: Expr[Any])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val pos = Term.of(x).underlyingArgument.pos - report.error("here is the the argument is " + Term.of(x).underlyingArgument.show, pos) - report.error("here (+5) is the the argument is " + Term.of(x).underlyingArgument.show, Position(pos.sourceFile, pos.start + 5, pos.end + 5)) + val pos = x.asTerm.underlyingArgument.pos + report.error("here is the the argument is " + x.asTerm.underlyingArgument.show, pos) + report.error("here (+5) is the the argument is " + x.asTerm.underlyingArgument.show, Position(pos.sourceFile, pos.start + 5, pos.end + 5)) '{} } diff --git a/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala b/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala index 8d94a4fe9304..87497ea6fc99 100644 --- a/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala +++ b/tests/neg-macros/tasty-string-interpolator-position-a/Macro_1.scala @@ -11,7 +11,7 @@ object FIntepolator { def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes) : Expr[String] = { import quotes.reflect._ - report.error("there are no parts", Term.of(strCtxExpr).underlyingArgument.pos) + report.error("there are no parts", strCtxExpr.asTerm.underlyingArgument.pos) '{ ($strCtxExpr).s($argsExpr: _*) } } diff --git a/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala b/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala index 7bb1cd5d5341..e17734b11e85 100644 --- a/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala +++ b/tests/neg-macros/tasty-string-interpolator-position-b/Macro_1.scala @@ -10,7 +10,7 @@ object Macro { object FIntepolator { def apply(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using Quotes) : Expr[String] = { import quotes.reflect._ - report.error("there are no args", Term.of(argsExpr).underlyingArgument.pos) + report.error("there are no args", argsExpr.asTerm.underlyingArgument.pos) '{ ($strCtxExpr).s($argsExpr: _*) } } diff --git a/tests/neg-staging/i5941/macro_1.scala b/tests/neg-staging/i5941/macro_1.scala index 3977d33b4b24..150c3c7d5b12 100644 --- a/tests/neg-staging/i5941/macro_1.scala +++ b/tests/neg-staging/i5941/macro_1.scala @@ -17,10 +17,10 @@ object Lens { import util._ // obj.copy(field = value) def setterBody(obj: Expr[S], value: Expr[T], field: String): Expr[S] = - Select.overloaded(Term.of(obj), "copy", Nil, NamedArg(field, Term.of(value)) :: Nil, TypeBounds.empty).asExprOf[S] + Select.overloaded(obj.asTerm, "copy", Nil, NamedArg(field, value.asTerm) :: Nil, TypeBounds.empty).asExprOf[S] // exception: Term.of(getter).underlyingArgument - Term.of(getter) match { + getter.asTerm match { case Inlined( None, Nil, Block( diff --git a/tests/pending/run/tasty-comments/quoted_1.scala b/tests/pending/run/tasty-comments/quoted_1.scala index 2fe63a98dae6..60de1ef1c2d5 100644 --- a/tests/pending/run/tasty-comments/quoted_1.scala +++ b/tests/pending/run/tasty-comments/quoted_1.scala @@ -9,7 +9,7 @@ object Macros { def impl[T](x: Expr[T])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(x) + val tree = x.asTerm tree.symbol.comment.map(_.raw) match { case Some(str) => '{ println(${str}) } case None => '{ println() } diff --git a/tests/pos-macros/i10151/Macro_1.scala b/tests/pos-macros/i10151/Macro_1.scala index f06b756ac735..f5170c83da12 100644 --- a/tests/pos-macros/i10151/Macro_1.scala +++ b/tests/pos-macros/i10151/Macro_1.scala @@ -60,7 +60,7 @@ object X: case l@Literal(x) => l.asExpr match case '{ $l: lit } => - Term.of('{ CBM.pure(${term.asExprOf[lit]}) }) + '{ CBM.pure(${term.asExprOf[lit]}) }.asTerm case other => throw RuntimeException(s"Not supported $other") @@ -89,5 +89,5 @@ object X: } changes.transformTerm(body)(Symbol.spliceOwner) - val r = transform(Term.of(f)).asExprOf[CB[T]] + val r = transform(f.asTerm).asExprOf[CB[T]] r diff --git a/tests/pos-macros/i10211/Macro_1.scala b/tests/pos-macros/i10211/Macro_1.scala index fe9b0cbee308..ebf9b76ff77e 100644 --- a/tests/pos-macros/i10211/Macro_1.scala +++ b/tests/pos-macros/i10211/Macro_1.scala @@ -67,11 +67,11 @@ object X: val tb = transform(b).asExprOf[CB[Int]] val mt = MethodType(List("p"))(_ => List(b.tpe.widen), _ => TypeRepr.of[Boolean]) val mapLambda = Lambda(Symbol.spliceOwner, mt, (_, x) => Select.overloaded(obj,"==",List(),List(x.head.asInstanceOf[Term]))).asExprOf[Int=>Boolean] - Term.of('{ CBM.map($tb)($mapLambda) }) + '{ CBM.map($tb)($mapLambda) }.asTerm case Block(stats, last) => Block(stats, transform(last)) case Inlined(x,List(),body) => transform(body) case l@Literal(x) => - Term.of('{ CBM.pure(${term.asExpr}) }) + '{ CBM.pure(${term.asExpr}) }.asTerm case other => throw RuntimeException(s"Not supported $other") @@ -99,4 +99,4 @@ object X: } changes.transformTerm(body)(Symbol.spliceOwner) - transform(Term.of(f)).asExprOf[CB[T]] + transform(f.asTerm).asExprOf[CB[T]] diff --git a/tests/pos-macros/i6171/Macro_1.scala b/tests/pos-macros/i6171/Macro_1.scala index e04b47dc7c78..e996206bc24f 100644 --- a/tests/pos-macros/i6171/Macro_1.scala +++ b/tests/pos-macros/i6171/Macro_1.scala @@ -6,7 +6,7 @@ object scalatest { def assertImpl(x: Expr[Any])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - Term.of(x).underlyingArgument + x.asTerm.underlyingArgument '{ () } } } diff --git a/tests/pos-macros/i6535/Macro_1.scala b/tests/pos-macros/i6535/Macro_1.scala index aaec24d82ba5..a00360a2dddb 100644 --- a/tests/pos-macros/i6535/Macro_1.scala +++ b/tests/pos-macros/i6535/Macro_1.scala @@ -9,7 +9,7 @@ object scalatest { import util._ import ValDef.let - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => let(Symbol.spliceOwner, lhs) { left => let(Symbol.spliceOwner, rhs) { right => @@ -19,7 +19,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] diff --git a/tests/pos-macros/i7011/Macros_1.scala b/tests/pos-macros/i7011/Macros_1.scala index a321af1fa825..2854ccffe103 100644 --- a/tests/pos-macros/i7011/Macros_1.scala +++ b/tests/pos-macros/i7011/Macros_1.scala @@ -5,7 +5,7 @@ inline def mcr(body: => Any): Unit = ${mcrImpl('body)} def mcrImpl[T](body: Expr[Any])(using Quotes) : Expr[Any] = { import quotes.reflect._ - val bTree = Term.of(body) + val bTree = body.asTerm val under = bTree.underlyingArgument val res = '{Box(${under.asInstanceOf[Term].asExpr})} diff --git a/tests/pos-macros/i7030/Macros_1.scala b/tests/pos-macros/i7030/Macros_1.scala index d6c03b7ff323..9a4b8e277bed 100644 --- a/tests/pos-macros/i7030/Macros_1.scala +++ b/tests/pos-macros/i7030/Macros_1.scala @@ -7,5 +7,5 @@ def innerImpl(exprs: Expr[Any])(using Quotes): Expr[Any] = inline def outer(expr: => Any): Any = ${outerImpl('expr)} def outerImpl(body: Expr[Any])(using Quotes): Expr[Any] = { import quotes.reflect._ - Term.of(body).underlyingArgument.asExpr + body.asTerm.underlyingArgument.asExpr } diff --git a/tests/pos-macros/i8325/Macro_1.scala b/tests/pos-macros/i8325/Macro_1.scala index 83aed7231340..b3f14e80157c 100644 --- a/tests/pos-macros/i8325/Macro_1.scala +++ b/tests/pos-macros/i8325/Macro_1.scala @@ -13,7 +13,7 @@ object A: def transformImplExpr[A:Type](using Quotes)(expr: Expr[A]): Expr[A] = { import quotes.reflect._ - Term.of(expr) match { + expr.asTerm match { case Inlined(x,y,z) => transformImplExpr(z.asExpr.asInstanceOf[Expr[A]]) case Apply(fun,args) => '{ A.pure(${Apply(fun,args).asExpr.asInstanceOf[Expr[A]]}) } case other => expr diff --git a/tests/pos-macros/i8325b/Macro_1.scala b/tests/pos-macros/i8325b/Macro_1.scala index 3070a8e19e21..aa4255f6f3a0 100644 --- a/tests/pos-macros/i8325b/Macro_1.scala +++ b/tests/pos-macros/i8325b/Macro_1.scala @@ -13,7 +13,7 @@ object A: def transformImplExpr[A:Type](using Quotes)(expr: Expr[A]): Expr[A] = { import quotes.reflect._ - Term.of(expr) match { + expr.asTerm match { case Inlined(x,y,z) => transformImplExpr(z.asExpr.asInstanceOf[Expr[A]]) case r@Apply(fun,args) => '{ A.pure(${r.asExpr.asInstanceOf[Expr[A]]}) } diff --git a/tests/pos-macros/i8866/Macro_1.scala b/tests/pos-macros/i8866/Macro_1.scala index 88a5bb5d54fd..d6f33392e211 100644 --- a/tests/pos-macros/i8866/Macro_1.scala +++ b/tests/pos-macros/i8866/Macro_1.scala @@ -17,7 +17,7 @@ object Macro { ValDef.let( Symbol.spliceOwner, Select.unique( - Term.of('{ OtherMacro }), + '{ OtherMacro }.asTerm, "apply" ) )(identity).asExprOf[Int] diff --git a/tests/pos-macros/i8866b/Macro_1.scala b/tests/pos-macros/i8866b/Macro_1.scala index d3f19fa1a007..71e00123ba56 100644 --- a/tests/pos-macros/i8866b/Macro_1.scala +++ b/tests/pos-macros/i8866b/Macro_1.scala @@ -12,7 +12,7 @@ object Macro { ValDef.let( Symbol.spliceOwner, Select.unique( - Term.of('{ Other }), + '{ Other }.asTerm, "apply" ) )(identity).asExprOf[Int] diff --git a/tests/pos-macros/i9251/Macro_1.scala b/tests/pos-macros/i9251/Macro_1.scala index c6ac626f08b8..f055d1f595a8 100644 --- a/tests/pos-macros/i9251/Macro_1.scala +++ b/tests/pos-macros/i9251/Macro_1.scala @@ -21,7 +21,7 @@ object Async { def checkPrintTypeImpl[F[_]:Type,T:Type](f: Expr[T])(using Quotes): Expr[Unit] = import quotes.reflect._ - val fu = Term.of(f) + val fu = f.asTerm fu match case Inlined(_,_,Block(_,Apply(TypeApply(Select(q,n),tparams),List(param)))) => param.tpe match diff --git a/tests/pos-macros/i9518/Macro_1.scala b/tests/pos-macros/i9518/Macro_1.scala index dfee4799bbbd..c5507da6ba4b 100644 --- a/tests/pos-macros/i9518/Macro_1.scala +++ b/tests/pos-macros/i9518/Macro_1.scala @@ -7,7 +7,7 @@ inline def shift : Unit = ${ shiftTerm } def shiftTerm(using Quotes): Expr[Unit] = { import quotes.reflect._ - val nTree = Term.of('{ ??? : CB[Int] }) + val nTree = '{ ??? : CB[Int] }.asTerm val tp1 = TypeRepr.of[CB[Int]] val tp2 = TypeRepr.of[([X] =>> CB[X])[Int]] val ta = Type.of[[X] =>> CB[X]] diff --git a/tests/pos-macros/i9687/Macro_1.scala b/tests/pos-macros/i9687/Macro_1.scala index b65f28d7a104..267b4cbe8bc6 100644 --- a/tests/pos-macros/i9687/Macro_1.scala +++ b/tests/pos-macros/i9687/Macro_1.scala @@ -24,8 +24,8 @@ object X { def transformImpl[A:Type](x:Expr[A])(using Quotes):Expr[A] = { import quotes.reflect._ - val slowPath = Term.of('{ SlowPath }) - val fastPath = Term.of('{ FastPath }) + val slowPath = '{ SlowPath }.asTerm + val fastPath = '{ FastPath }.asTerm val transformer = new TreeMap() { override def transformTerm(term:Term)(owner: Symbol):Term = { term match @@ -37,7 +37,7 @@ object X { case _ => super.transformTerm(term)(owner) } } - val r = transformer.transformTerm(Term.of(x))(Symbol.spliceOwner).asExprOf[A] + val r = transformer.transformTerm(x.asTerm)(Symbol.spliceOwner).asExprOf[A] s"result: ${r.show}" r } diff --git a/tests/pos-macros/i9894/Macro_1.scala b/tests/pos-macros/i9894/Macro_1.scala index bcecb887c8d3..7135cb6a7029 100644 --- a/tests/pos-macros/i9894/Macro_1.scala +++ b/tests/pos-macros/i9894/Macro_1.scala @@ -36,7 +36,7 @@ object X: case Block(stats, last) => Block(stats, transform(last)) case Inlined(x,List(),body) => transform(body) case l@Literal(x) => - Term.of('{ CBM.pure(${term.asExpr}) }) + '{ CBM.pure(${term.asExpr}) }.asTerm case other => throw RuntimeException(s"Not supported $other") @@ -64,4 +64,4 @@ object X: } changes.transformTerm(body)(Symbol.spliceOwner) - transform(Term.of(f)).asExprOf[CB[T]] + transform(f.asTerm).asExprOf[CB[T]] diff --git a/tests/pos-macros/treemap-unapply/Macro.scala b/tests/pos-macros/treemap-unapply/Macro.scala index 09bc5f91a3a1..7e389e666fa7 100644 --- a/tests/pos-macros/treemap-unapply/Macro.scala +++ b/tests/pos-macros/treemap-unapply/Macro.scala @@ -3,6 +3,6 @@ import scala.quoted._ inline def mcr(x: => Unit): Unit = ${mcrImpl('x)} def mcrImpl(x: Expr[Unit])(using Quotes) : Expr[Unit] = import quotes.reflect._ - val tr: Term = Term.of(x) + val tr: Term = x.asTerm object m extends TreeMap m.transformTerm(tr)(Symbol.spliceOwner).asExprOf[Unit] diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala b/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala index 586f245c7459..e30bf8af85ae 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-2/Macro_1.scala @@ -7,7 +7,7 @@ object Foo { def inspectBodyImpl(x: Expr[Int])(using Quotes) : Expr[String] = { import quotes.reflect._ - Term.of(x) match { + x.asTerm match { case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.show(using Printer.TreeStructure)) case arg => Expr(arg.symbol.tree.show(using Printer.TreeStructure)) // TODO should all by name parameters be in an inline node? } diff --git a/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala b/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala index 9ddaea06bc5a..6bdd99bfe7fa 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-definitions-3/Macro_1.scala @@ -7,7 +7,7 @@ object Foo { def inspectBodyImpl(x: Expr[Int])(using Quotes) : Expr[String] = { import quotes.reflect._ - Term.of(x) match { + x.asTerm match { case Inlined(None, Nil, arg) => Expr(arg.symbol.tree.show(using Printer.TreeStructure)) case arg => Expr(arg.symbol.tree.show(using Printer.TreeStructure)) // TODO should all by name parameters be in an inline node? } diff --git a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala index 7593a4af18b0..da28a2616e8e 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-extractors-owners/quoted_1.scala @@ -12,7 +12,7 @@ object Macros { val output = myTraverser(buff) - val tree = Term.of(x) + val tree = x.asTerm output.traverseTree(tree)(Symbol.spliceOwner) '{print(${Expr(buff.result())})} } diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala index 9af2c09daccf..53cecc556fee 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-1/quoted_1.scala @@ -13,7 +13,7 @@ object Foo { if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.show(using Printer.TreeStructure)) else '{"NO DEFINTION"} - Term.of(x) match { + x.asTerm match { case Inlined(None, Nil, arg) => definitionString(arg.symbol) case arg => definitionString(arg.symbol) // TODO should all by name parameters be in an inline node } diff --git a/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala b/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala index b9a3d7c7e4fc..81550be6ca02 100644 --- a/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala +++ b/tests/run-custom-args/Yretain-trees/tasty-load-tree-2/quoted_1.scala @@ -12,7 +12,7 @@ object Foo { if sym.isClassDef || sym.isDefDef || sym.isValDef then Expr(sym.tree.show(using Printer.TreeStructure)) else '{"NO DEFINTION"} - Term.of(x) match { + x.asTerm match { case Inlined(None, Nil, arg) => definitionString(arg.symbol) case arg => definitionString(arg.symbol) // TODO should all by name parameters be in an inline node } diff --git a/tests/run-macros/exports/Macro_2.scala b/tests/run-macros/exports/Macro_2.scala index 3c0a3c04fb59..8ab557efe02a 100644 --- a/tests/run-macros/exports/Macro_2.scala +++ b/tests/run-macros/exports/Macro_2.scala @@ -14,15 +14,15 @@ private def visitExportsExprMapImpl[T: Type](e: Expr[T], f: Expr[T => Any])(usin private def visitExportsTreeMapImpl[T: Type](e: Expr[T], f: Expr[T => Any])(using Quotes): Expr[Any] = import quotes.reflect._ object m extends TreeMap - '{$f(${m.transformTerm(Term.of(e))(Symbol.spliceOwner).asExprOf})} + '{$f(${m.transformTerm(e.asTerm)(Symbol.spliceOwner).asExprOf})} private def visitExportsShowImpl[T: Type](e: Expr[T])(using Quotes): Expr[Any] = import quotes.reflect._ - '{println(${Expr(Term.of(e).show)})} + '{println(${Expr(e.asTerm.show)})} private def visitExportsShowExtractImpl[T: Type](e: Expr[T])(using Quotes): Expr[Any] = import quotes.reflect._ - '{println(${Expr(Term.of(e).show(using Printer.TreeStructure))})} + '{println(${Expr(e.asTerm.show(using Printer.TreeStructure))})} private object IdempotentExprMap extends ExprMap { @@ -43,7 +43,7 @@ private def traverseExportsImpl(e: Expr[Any], f: Expr[String => Any])(using Quot } val res = - ExportAccumulator.foldTree(mutable.Buffer.empty, Term.of(e))(Symbol.spliceOwner).mkString(", ") + ExportAccumulator.foldTree(mutable.Buffer.empty, e.asTerm)(Symbol.spliceOwner).mkString(", ") '{ $f(${Expr(res)}) } } diff --git a/tests/run-macros/f-interpolation-1/FQuote_1.scala b/tests/run-macros/f-interpolation-1/FQuote_1.scala index c61837b13999..725d494c80d4 100644 --- a/tests/run-macros/f-interpolation-1/FQuote_1.scala +++ b/tests/run-macros/f-interpolation-1/FQuote_1.scala @@ -31,7 +31,7 @@ object FQuote { tree.symbol.fullName == "scala.StringContext$.apply" // FQuote.SCOps(StringContext.apply([p0, ...]: String*) - val parts = Term.of(receiver).underlyingArgument match { + val parts = receiver.asTerm.underlyingArgument match { case Apply(conv, List(Apply(fun, List(Typed(Repeated(values, _), _))))) if isSCOpsConversion(conv) && isStringContextApply(fun) && @@ -43,7 +43,7 @@ object FQuote { } // [a0, ...]: Any* - val Typed(Repeated(allArgs, _), _) = Term.of(args).underlyingArgument + val Typed(Repeated(allArgs, _), _) = args.asTerm.underlyingArgument for ((arg, part) <- allArgs.zip(parts.tail)) { if (part.startsWith("%d") && !(arg.tpe <:< TypeRepr.of[Int])) { diff --git a/tests/run-macros/i10011/Macro_1.scala b/tests/run-macros/i10011/Macro_1.scala index 376a39ab1ae1..b195d27b3986 100644 --- a/tests/run-macros/i10011/Macro_1.scala +++ b/tests/run-macros/i10011/Macro_1.scala @@ -5,5 +5,5 @@ inline def printPos[T](inline expr: T): (Int, Int) = private def printPos[T](expr: Expr[T])(using Quotes): Expr[(Int, Int)] = import quotes.reflect._ - val pos = Term.of(expr).pos + val pos = expr.asTerm.pos Expr((pos.start, pos.end)) diff --git a/tests/run-macros/i5119/Macro_1.scala b/tests/run-macros/i5119/Macro_1.scala index 933725164463..fd2b6c80b6f5 100644 --- a/tests/run-macros/i5119/Macro_1.scala +++ b/tests/run-macros/i5119/Macro_1.scala @@ -8,6 +8,6 @@ object Macro { def impl(sc: Expr[StringContext], args: Expr[Seq[Any]])(using q: Quotes) : Expr[String] = { import q.reflect._ given Printer[Tree] = Printer.TreeStructure - Expr(Term.of(sc).underlyingArgument.show + "\n" + Term.of(args).underlyingArgument.show) + Expr(sc.asTerm.underlyingArgument.show + "\n" + args.asTerm.underlyingArgument.show) } } diff --git a/tests/run-macros/i5119b/Macro_1.scala b/tests/run-macros/i5119b/Macro_1.scala index ad18af6b1104..fb22b0a04e0f 100644 --- a/tests/run-macros/i5119b/Macro_1.scala +++ b/tests/run-macros/i5119b/Macro_1.scala @@ -8,6 +8,6 @@ object Macro { def impl(arg1: Expr[Any], arg2: Expr[Any])(using q: Quotes) : Expr[String] = import q.reflect._ given Printer[Tree] = Printer.TreeStructure - Expr(Term.of(arg1).underlyingArgument.show + "\n" + Term.of(arg2).underlyingArgument.show) + Expr(arg1.asTerm.underlyingArgument.show + "\n" + arg2.asTerm.underlyingArgument.show) } diff --git a/tests/run-macros/i5533/Macro_1.scala b/tests/run-macros/i5533/Macro_1.scala index 18c7d48f20cc..701982a9c7a1 100644 --- a/tests/run-macros/i5533/Macro_1.scala +++ b/tests/run-macros/i5533/Macro_1.scala @@ -10,7 +10,7 @@ object scalatest { def assertImpl(condition: Expr[Boolean])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(condition) + val tree = condition.asTerm val expr = tree.asExprOf[Boolean] diff --git a/tests/run-macros/i5533b/Macro_1.scala b/tests/run-macros/i5533b/Macro_1.scala index ec093670e2dc..bd172b4edbf3 100644 --- a/tests/run-macros/i5533b/Macro_1.scala +++ b/tests/run-macros/i5533b/Macro_1.scala @@ -8,7 +8,7 @@ object scalatest { def assertImpl(condition: Expr[Boolean])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(condition) + val tree = condition.asTerm def exprStr: String = condition.show tree.underlyingArgument match { diff --git a/tests/run-macros/i5536/Macro_1.scala b/tests/run-macros/i5536/Macro_1.scala index 541e089934ba..bd0cc2402077 100644 --- a/tests/run-macros/i5536/Macro_1.scala +++ b/tests/run-macros/i5536/Macro_1.scala @@ -5,7 +5,7 @@ object scalatest { def assertImpl(condition: Expr[Boolean])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(condition) + val tree = condition.asTerm def exprStr: String = condition.show tree.underlyingArgument match { diff --git a/tests/run-macros/i5629/Macro_1.scala b/tests/run-macros/i5629/Macro_1.scala index 159df2b24838..641f276b7da0 100644 --- a/tests/run-macros/i5629/Macro_1.scala +++ b/tests/run-macros/i5629/Macro_1.scala @@ -6,7 +6,7 @@ object Macros { def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val b = Term.of(cond).underlyingArgument.asExprOf[Boolean] + val b = cond.asTerm.underlyingArgument.asExprOf[Boolean] '{ scala.Predef.assert($b) } } diff --git a/tests/run-macros/i5715/Macro_1.scala b/tests/run-macros/i5715/Macro_1.scala index 199b00433500..e0d476d5eb16 100644 --- a/tests/run-macros/i5715/Macro_1.scala +++ b/tests/run-macros/i5715/Macro_1.scala @@ -7,7 +7,7 @@ object scalatest { def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case app @ Apply(select @ Select(lhs, op), rhs :: Nil) => val cond = Apply(Select.copy(select)(lhs, "exists"), rhs :: Nil).asExprOf[Boolean] '{ scala.Predef.assert($cond) } diff --git a/tests/run-macros/i5941/macro_1.scala b/tests/run-macros/i5941/macro_1.scala index 5bb055ee9422..13b8e62c1116 100644 --- a/tests/run-macros/i5941/macro_1.scala +++ b/tests/run-macros/i5941/macro_1.scala @@ -45,11 +45,11 @@ object Lens { } } - // exception: Term.of(getter).underlyingArgument - Term.of(getter) match { + // exception: getter.asTerm.underlyingArgument + getter.asTerm match { case Function(param :: Nil, Path(o, parts)) if o.symbol == param.symbol => '{ - val setter = (t: T) => (s: S) => ${ setterBody(Term.of('s), Term.of('t), parts).asExprOf[S] } + val setter = (t: T) => (s: S) => ${ setterBody('s.asTerm, 't.asTerm, parts).asExprOf[S] } apply($getter)(setter) } case _ => @@ -116,9 +116,9 @@ object Iso { '{???} } else '{ // (p: S) => p._1 - val to = (p: S) => ${ Select.unique(Term.of('p), "_1").asExprOf[A] } + val to = (p: S) => ${ Select.unique('p.asTerm, "_1").asExprOf[A] } // (p: A) => S(p) - val from = (p: A) => ${ Select.overloaded(Ident(companion), "apply", Nil, Term.of('p) :: Nil).asExprOf[S] } + val from = (p: A) => ${ Select.overloaded(Ident(companion), "apply", Nil, 'p.asTerm :: Nil).asExprOf[S] } apply(from)(to) } } diff --git a/tests/run-macros/i6171/Macro_1.scala b/tests/run-macros/i6171/Macro_1.scala index 4e1cc1ba89b7..f34e1df8aca0 100644 --- a/tests/run-macros/i6171/Macro_1.scala +++ b/tests/run-macros/i6171/Macro_1.scala @@ -12,7 +12,7 @@ object scalatest { case tp: MethodType => tp.isImplicit case _ => false - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => ValDef.let(Symbol.spliceOwner, lhs) { left => ValDef.let(Symbol.spliceOwner, rhs) { right => @@ -22,7 +22,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] @@ -36,7 +36,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] diff --git a/tests/run-macros/i6679/Macro_1.scala b/tests/run-macros/i6679/Macro_1.scala index 6d75b0202368..663b23f7e7cd 100644 --- a/tests/run-macros/i6679/Macro_1.scala +++ b/tests/run-macros/i6679/Macro_1.scala @@ -4,7 +4,7 @@ def makeMatch[A: Type](head : Expr[A])(using qctx : Quotes) : Expr[Unit] = { import quotes.reflect._ val sacrifice = '{ $head match { case _ => ??? } } - Term.of(sacrifice) + sacrifice.asTerm '{ println("Ok") } } diff --git a/tests/run-macros/i7887/Macro_1.scala b/tests/run-macros/i7887/Macro_1.scala index 4c7b36291bc4..dc867bc512cd 100644 --- a/tests/run-macros/i7887/Macro_1.scala +++ b/tests/run-macros/i7887/Macro_1.scala @@ -1,10 +1,10 @@ def myMacroImpl(a: quoted.Expr[_])(using qctx: quoted.Quotes) = { import scala.quoted.quotes.reflect._ def typed[A] = { - implicit val t: quoted.Type[A] = Term.of(a).tpe.widen.asType.asInstanceOf[quoted.Type[A]] + implicit val t: quoted.Type[A] = a.asTerm.tpe.widen.asType.asInstanceOf[quoted.Type[A]] '{ type T = A - ${Term.of(a).asExprOf[T]} + ${a.asTerm.asExprOf[T]} } } diff --git a/tests/run-macros/i7898/Macro_1.scala b/tests/run-macros/i7898/Macro_1.scala index 6b1a0e59d8ff..8ac47bb1e1bd 100644 --- a/tests/run-macros/i7898/Macro_1.scala +++ b/tests/run-macros/i7898/Macro_1.scala @@ -4,7 +4,7 @@ object Main { def myMacroImpl(body: Expr[_])(using Quotes) : Expr[_] = { import quotes.reflect._ - val bodyTerm = Term.of(underlyingArgument(body)) + val bodyTerm = underlyingArgument(body).asTerm val showed = bodyTerm.show '{ println(${Expr(showed)}) @@ -18,5 +18,5 @@ object Main { def underlyingArgument[T](expr: Expr[T])(using Quotes): Expr[T] = import quotes.reflect._ - Term.of(expr).underlyingArgument.asExpr.asInstanceOf[Expr[T]] + expr.asTerm.underlyingArgument.asExpr.asInstanceOf[Expr[T]] } diff --git a/tests/run-macros/i8007/Macro_2.scala b/tests/run-macros/i8007/Macro_2.scala index 506d09a13888..4e38c86fd4b0 100644 --- a/tests/run-macros/i8007/Macro_2.scala +++ b/tests/run-macros/i8007/Macro_2.scala @@ -30,7 +30,7 @@ object Macro2 { val body: Expr[T] => Expr[String] = elem => fields.reverse.foldLeft(Expr("")){ (acc, field) => - val res = Select.unique(Term.of(elem), field).asExpr + val res = Select.unique(elem.asTerm, field).asExpr '{ $res.toString + " " + $acc } } diff --git a/tests/run-macros/inferred-repeated-result/test_1.scala b/tests/run-macros/inferred-repeated-result/test_1.scala index 379f877a70fd..c3e7d0a2ac5b 100644 --- a/tests/run-macros/inferred-repeated-result/test_1.scala +++ b/tests/run-macros/inferred-repeated-result/test_1.scala @@ -5,7 +5,7 @@ object Macros { def impl[T](expr: Expr[T])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(expr) + val tree = expr.asTerm val methods = tree.tpe.classSymbol.get.declaredMethods.map { m => diff --git a/tests/run-macros/paramSymss/Macro_1.scala b/tests/run-macros/paramSymss/Macro_1.scala index 08c1841899cb..4c886b3476cf 100644 --- a/tests/run-macros/paramSymss/Macro_1.scala +++ b/tests/run-macros/paramSymss/Macro_1.scala @@ -6,7 +6,7 @@ inline def showParamSyms(inline x: Any): String = def showParamSymsExpr(using Quotes)(x: Expr[Any]): Expr[String] = import quotes.reflect._ val '{ $y: Any } = x // Drop Inlined not to access the symbol - val sym = Term.of(y).symbol + val sym = y.asTerm.symbol Expr( s"""sym: ${sym.fullName} |paramSymss: ${sym.paramSymss.map(_.map(_.fullName))} diff --git a/tests/run-macros/quote-matcher-runtime/quoted_1.scala b/tests/run-macros/quote-matcher-runtime/quoted_1.scala index 000a5f8ba232..e172073b997e 100644 --- a/tests/run-macros/quote-matcher-runtime/quoted_1.scala +++ b/tests/run-macros/quote-matcher-runtime/quoted_1.scala @@ -17,8 +17,8 @@ object Macros { } '{ - println("Scrutinee: " + ${Expr(Term.of(a).show)}) - println("Pattern: " + ${Expr(Term.of(b).show)}) + println("Scrutinee: " + ${Expr(a.asTerm.show)}) + println("Pattern: " + ${Expr(b.asTerm.show)}) println("Result: " + ${Expr(res.toString)}) println() } diff --git a/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala index 3859f395866b..34f814156b9a 100644 --- a/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-1/quoted_1.scala @@ -21,7 +21,7 @@ object Macros { case _ => import quotes.reflect._ - report.error("Expected explicit DSL", Term.of(e).pos) + report.error("Expected explicit DSL", e.asTerm.pos) '{ ??? } } diff --git a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala index 1211f35f42e4..d2738d0232a9 100644 --- a/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-2/quoted_1.scala @@ -39,7 +39,7 @@ object Macros { case _ => import quotes.reflect._ - report.error("Expected explicit DSL " + e.show, Term.of(e).pos) + report.error("Expected explicit DSL " + e.show, e.asTerm.pos) ??? } @@ -53,7 +53,7 @@ object Macros { ) case _ => import quotes.reflect._ - report.error("Expected explicit DSL => DSL " + e.show, Term.of(e).pos) + report.error("Expected explicit DSL => DSL " + e.show, e.asTerm.pos) ??? } @@ -66,11 +66,11 @@ object UnsafeExpr { def open[T1, R, X](f: Expr[T1 => R])(content: (Expr[R], [t] => Expr[t] => Expr[T1] => Expr[t]) => X)(using Quotes): X = { import quotes.reflect._ val (params, bodyExpr) = paramsAndBody[R](f) - content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](Term.of(e), params, List(Term.of(v))).asExpr.asInstanceOf[Expr[t]]) + content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](e.asTerm, params, List(v.asTerm)).asExpr.asInstanceOf[Expr[t]]) } private def paramsAndBody[R](using Quotes)(f: Expr[Any]): (List[quotes.reflect.ValDef], Expr[R]) = { import quotes.reflect._ - val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = Term.of(f).etaExpand(Symbol.spliceOwner) + val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = f.asTerm.etaExpand(Symbol.spliceOwner) (params, body.asExpr.asInstanceOf[Expr[R]]) } diff --git a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala index 8951f84963cb..61f18aa49a84 100644 --- a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala @@ -79,11 +79,11 @@ object UnsafeExpr { def open[T1, R, X](f: Expr[T1 => R])(content: (Expr[R], [t] => Expr[t] => Expr[T1] => Expr[t]) => X)(using Quotes): X = { import quotes.reflect._ val (params, bodyExpr) = paramsAndBody[R](f) - content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](Term.of(e), params, List(Term.of(v))).asExpr.asInstanceOf[Expr[t]]) + content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](e.asTerm, params, List(v.asTerm)).asExpr.asInstanceOf[Expr[t]]) } private def paramsAndBody[R](using Quotes)(f: Expr[Any]): (List[quotes.reflect.ValDef], Expr[R]) = { import quotes.reflect._ - val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = Term.of(f).etaExpand(Symbol.spliceOwner) + val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = f.asTerm.etaExpand(Symbol.spliceOwner) (params, body.asExpr.asInstanceOf[Expr[R]]) } diff --git a/tests/run-macros/quote-matching-open/Macro_1.scala b/tests/run-macros/quote-matching-open/Macro_1.scala index 1d31d0ccc824..1b8bd6975101 100644 --- a/tests/run-macros/quote-matching-open/Macro_1.scala +++ b/tests/run-macros/quote-matching-open/Macro_1.scala @@ -19,22 +19,22 @@ object UnsafeExpr { def open[T1, R, X](f: Expr[T1 => R])(content: (Expr[R], [t] => Expr[t] => Expr[T1] => Expr[t]) => X)(using Quotes): X = { import quotes.reflect._ val (params, bodyExpr) = paramsAndBody[R](f) - content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](Term.of(e), params, List(Term.of(v))).asExpr.asInstanceOf[Expr[t]]) + content(bodyExpr, [t] => (e: Expr[t]) => (v: Expr[T1]) => bodyFn[t](e.asTerm, params, List(v.asTerm)).asExpr.asInstanceOf[Expr[t]]) } def open[T1, T2, R, X](f: Expr[(T1, T2) => R])(content: (Expr[R], [t] => Expr[t] => (Expr[T1], Expr[T2]) => Expr[t]) => X)(using Quotes)(using DummyImplicit): X = { import quotes.reflect._ val (params, bodyExpr) = paramsAndBody[R](f) - content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2]) => bodyFn[t](Term.of(e), params, List(Term.of(v1), Term.of(v2))).asExpr.asInstanceOf[Expr[t]]) + content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2]) => bodyFn[t](e.asTerm, params, List(v1.asTerm, v2.asTerm)).asExpr.asInstanceOf[Expr[t]]) } def open[T1, T2, T3, R, X](f: Expr[(T1, T2, T3) => R])(content: (Expr[R], [t] => Expr[t] => (Expr[T1], Expr[T2], Expr[T3]) => Expr[t]) => X)(using Quotes)(using DummyImplicit, DummyImplicit): X = { import quotes.reflect._ val (params, bodyExpr) = paramsAndBody[R](f) - content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2], v3: Expr[T3]) => bodyFn[t](Term.of(e), params, List(Term.of(v1), Term.of(v2), Term.of(v3))).asExpr.asInstanceOf[Expr[t]]) + content(bodyExpr, [t] => (e: Expr[t]) => (v1: Expr[T1], v2: Expr[T2], v3: Expr[T3]) => bodyFn[t](e.asTerm, params, List(v1.asTerm, v2.asTerm, v3.asTerm)).asExpr.asInstanceOf[Expr[t]]) } private def paramsAndBody[R](using Quotes)(f: Expr[Any]): (List[quotes.reflect.ValDef], Expr[R]) = { import quotes.reflect._ - val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = Term.of(f).etaExpand(Symbol.spliceOwner) + val Block(List(DefDef("$anonfun", Nil, List(params), _, Some(body))), Closure(Ident("$anonfun"), None)) = f.asTerm.etaExpand(Symbol.spliceOwner) (params, body.asExpr.asInstanceOf[Expr[R]]) } diff --git a/tests/run-macros/quoted-matching-docs/Macro_1.scala b/tests/run-macros/quoted-matching-docs/Macro_1.scala index bd4423e99fd8..ea0a6651998f 100644 --- a/tests/run-macros/quoted-matching-docs/Macro_1.scala +++ b/tests/run-macros/quoted-matching-docs/Macro_1.scala @@ -23,5 +23,5 @@ private def sumExpr(argsExpr: Expr[Seq[Int]])(using Quotes) : Expr[Int] = { object UnsafeExpr { def underlyingArgument[T](expr: Expr[T])(using Quotes): Expr[T] = import quotes.reflect._ - Term.of(expr).underlyingArgument.asExpr.asInstanceOf[Expr[T]] + expr.asTerm.underlyingArgument.asExpr.asInstanceOf[Expr[T]] } \ No newline at end of file diff --git a/tests/run-macros/refined-selectable-macro/Macro_1.scala b/tests/run-macros/refined-selectable-macro/Macro_1.scala index ab89c080a4f6..fc518d82fcde 100644 --- a/tests/run-macros/refined-selectable-macro/Macro_1.scala +++ b/tests/run-macros/refined-selectable-macro/Macro_1.scala @@ -17,7 +17,7 @@ object Macro { private def toTupleImpl(s: Expr[Selectable])(using qctx:Quotes) : Expr[Tuple] = { import quotes.reflect._ - val repr = Term.of(s).tpe.widenTermRefExpr.dealias + val repr = s.asTerm.tpe.widenTermRefExpr.dealias def rec(tpe: TypeRepr): List[(String, TypeRepr)] = { tpe match { @@ -51,7 +51,7 @@ object Macro { private def fromTupleImpl[T: Type](s: Expr[Tuple], newRecord: Expr[Array[(String, Any)] => T])(using qctx:Quotes) : Expr[Any] = { import quotes.reflect._ - val repr = Term.of(s).tpe.widenTermRefExpr.dealias + val repr = s.asTerm.tpe.widenTermRefExpr.dealias def isTupleCons(sym: Symbol): Boolean = sym.owner == defn.ScalaPackageClass && sym.name == "*:" diff --git a/tests/run-macros/reflect-dsl/assert_1.scala b/tests/run-macros/reflect-dsl/assert_1.scala index 2b1a6f7b29e4..9424226f6de9 100644 --- a/tests/run-macros/reflect-dsl/assert_1.scala +++ b/tests/run-macros/reflect-dsl/assert_1.scala @@ -12,7 +12,7 @@ object scalatest { case tp: MethodType => tp.isImplicit case _ => false - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case t @ Apply(sel @ Select(lhs, op), rhs :: Nil) => ValDef.let(Symbol.spliceOwner, lhs) { left => ValDef.let(Symbol.spliceOwner, rhs) { right => @@ -22,7 +22,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] @@ -36,7 +36,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] diff --git a/tests/run-macros/reflect-lambda/assert_1.scala b/tests/run-macros/reflect-lambda/assert_1.scala index edce3833f272..077635b93cef 100644 --- a/tests/run-macros/reflect-lambda/assert_1.scala +++ b/tests/run-macros/reflect-lambda/assert_1.scala @@ -8,7 +8,7 @@ object lib { import quotes.reflect._ import util._ - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case t @ Apply(Select(lhs, op), Lambda(param :: Nil, Apply(Select(a, "=="), b :: Nil)) :: Nil) if a.symbol == param.symbol || b.symbol == param.symbol => '{ scala.Predef.assert($cond) } diff --git a/tests/run-macros/reflect-pos-fun/assert_1.scala b/tests/run-macros/reflect-pos-fun/assert_1.scala index e8395b788fa5..712983517b01 100644 --- a/tests/run-macros/reflect-pos-fun/assert_1.scala +++ b/tests/run-macros/reflect-pos-fun/assert_1.scala @@ -8,13 +8,13 @@ object scalatest { import quotes.reflect._ import util._ - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case t @ Apply(TypeApply(Select(lhs, op), targs), rhs) => ValDef.let(Symbol.spliceOwner, lhs) { left => ValDef.let(Symbol.spliceOwner, rhs) { rs => val app = Select.overloaded(left, op, targs.map(_.tpe), rs) val b = app.asExprOf[Boolean] - Term.of('{ scala.Predef.assert($b) }) + '{ scala.Predef.assert($b) }.asTerm } }.asExprOf[Unit] } diff --git a/tests/run-macros/reflect-select-constructor/assert_1.scala b/tests/run-macros/reflect-select-constructor/assert_1.scala index 01e85812e590..3774fa5e98ba 100644 --- a/tests/run-macros/reflect-select-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-constructor/assert_1.scala @@ -12,7 +12,7 @@ object scalatest { case tp: MethodType => tp.isImplicit case _ => false - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => ValDef.let(Symbol.spliceOwner, lhs) { left => ValDef.let(Symbol.spliceOwner, rhs) { right => @@ -22,7 +22,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] @@ -36,7 +36,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] diff --git a/tests/run-macros/reflect-select-copy-2/assert_1.scala b/tests/run-macros/reflect-select-copy-2/assert_1.scala index 502a6e9493bd..8b9c535ab5b9 100644 --- a/tests/run-macros/reflect-select-copy-2/assert_1.scala +++ b/tests/run-macros/reflect-select-copy-2/assert_1.scala @@ -12,7 +12,7 @@ object scalatest { case tp: MethodType => tp.isImplicit case _ => false - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case Apply(sel @ Select(lhs, op), rhs :: Nil) => ValDef.let(Symbol.spliceOwner, lhs) { left => ValDef.let(Symbol.spliceOwner, rhs) { right => @@ -21,7 +21,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert(${b}) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] @@ -34,7 +34,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert(${b}) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] diff --git a/tests/run-macros/reflect-select-copy/assert_1.scala b/tests/run-macros/reflect-select-copy/assert_1.scala index cd489d08f364..af9a78fdb7d5 100644 --- a/tests/run-macros/reflect-select-copy/assert_1.scala +++ b/tests/run-macros/reflect-select-copy/assert_1.scala @@ -7,7 +7,7 @@ object scalatest { def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case Apply(select @ Select(lhs, op), rhs :: Nil) => val cond = Apply(Select.copy(select)(lhs, ">"), rhs :: Nil).asExprOf[Boolean] '{ scala.Predef.assert($cond) } diff --git a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala index 56d80b88f850..4f1e8e50b948 100644 --- a/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala +++ b/tests/run-macros/reflect-select-symbol-constructor/assert_1.scala @@ -12,7 +12,7 @@ object scalatest { case tp: MethodType => tp.isImplicit case _ => false - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case t @ Apply(sel @ Select(lhs, op), rhs :: Nil) => ValDef.let(Symbol.spliceOwner, lhs) { left => ValDef.let(Symbol.spliceOwner, rhs) { right => @@ -22,7 +22,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] @@ -36,7 +36,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] diff --git a/tests/run-macros/reflect-select-value-class/assert_1.scala b/tests/run-macros/reflect-select-value-class/assert_1.scala index 01e85812e590..3774fa5e98ba 100644 --- a/tests/run-macros/reflect-select-value-class/assert_1.scala +++ b/tests/run-macros/reflect-select-value-class/assert_1.scala @@ -12,7 +12,7 @@ object scalatest { case tp: MethodType => tp.isImplicit case _ => false - Term.of(cond).underlyingArgument match { + cond.asTerm.underlyingArgument match { case t @ Apply(Select(lhs, op), rhs :: Nil) => ValDef.let(Symbol.spliceOwner, lhs) { left => ValDef.let(Symbol.spliceOwner, rhs) { right => @@ -22,7 +22,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] @@ -36,7 +36,7 @@ object scalatest { val r = right.asExpr val b = result.asExprOf[Boolean] val code = '{ scala.Predef.assert($b) } - Term.of(code) + code.asTerm } } }.asExprOf[Unit] diff --git a/tests/run-macros/reflect-sourceCode/Macro_1.scala b/tests/run-macros/reflect-sourceCode/Macro_1.scala index 8a9173ad01ad..f2d85af7234f 100644 --- a/tests/run-macros/reflect-sourceCode/Macro_1.scala +++ b/tests/run-macros/reflect-sourceCode/Macro_1.scala @@ -6,6 +6,6 @@ object api { private def reflImpl[T](x: Expr[T])(implicit qctx: Quotes): Expr[String] = { import quotes.reflect._ - Expr(Term.of(x).pos.sourceCode.get) + Expr(x.asTerm.pos.sourceCode.get) } } diff --git a/tests/run-macros/tasty-argument-tree-1/quoted_1.scala b/tests/run-macros/tasty-argument-tree-1/quoted_1.scala index 2120e1c38a67..f25d0f2e3c18 100644 --- a/tests/run-macros/tasty-argument-tree-1/quoted_1.scala +++ b/tests/run-macros/tasty-argument-tree-1/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { def impl[T](x: Expr[T])(using q: Quotes) : Expr[Unit] = { import q.reflect._ - val tree = Term.of(x) + val tree = x.asTerm given Printer[Tree] = Printer.TreeStructure '{ println() diff --git a/tests/run-macros/tasty-construct-types/Macro_1.scala b/tests/run-macros/tasty-construct-types/Macro_1.scala index 70f2f753ec65..f883a6e2ba8b 100644 --- a/tests/run-macros/tasty-construct-types/Macro_1.scala +++ b/tests/run-macros/tasty-construct-types/Macro_1.scala @@ -27,7 +27,7 @@ object Macros { "T", TypeBounds(TypeRepr.of[Int], TypeRepr.of[Int])) val x6T = TypeRepr.of[List].appliedTo(List(TypeRepr.of[Int])) - val x7T = AnnotatedType(ConstantType(Constant.Int(7)), Term.of('{ new TestAnnotation })) + val x7T = AnnotatedType(ConstantType(Constant.Int(7)), '{ new TestAnnotation }.asTerm) val x8T = MatchType( TypeRepr.of[Int], diff --git a/tests/run-macros/tasty-create-method-symbol/Macro_1.scala b/tests/run-macros/tasty-create-method-symbol/Macro_1.scala index a6b7e521ad8e..eec0fa7147d2 100644 --- a/tests/run-macros/tasty-create-method-symbol/Macro_1.scala +++ b/tests/run-macros/tasty-create-method-symbol/Macro_1.scala @@ -20,10 +20,10 @@ object Macros { DefDef(sym1, { case List() => { case List(List(a, b)) => - Some(Term.of('{ ${ a.asExpr.asInstanceOf[Expr[Int]] } - ${ b.asExpr.asInstanceOf[Expr[Int]] } })) + Some('{ ${ a.asExpr.asInstanceOf[Expr[Int]] } - ${ b.asExpr.asInstanceOf[Expr[Int]] } }.asTerm) } }), - Term.of('{ assert(${ Apply(Ref(sym1), List(Literal(Constant.Int(2)), Literal(Constant.Int(3)))).asExpr.asInstanceOf[Expr[Int]] } == -1) })) + '{ assert(${ Apply(Ref(sym1), List(Literal(Constant.Int(2)), Literal(Constant.Int(3)))).asExpr.asInstanceOf[Expr[Int]] } == -1) }.asTerm) // test for no argument list (no Apply node) val sym2 : Symbol = Symbol.newMethod( @@ -39,7 +39,7 @@ object Macros { Some(Literal(Constant.Int(2))) } }), - Term.of('{ assert(${ Ref(sym2).asExpr.asInstanceOf[Expr[Int]] } == 2) })) + '{ assert(${ Ref(sym2).asExpr.asInstanceOf[Expr[Int]] } == 2) }.asTerm) // test for multiple argument lists val sym3 : Symbol = Symbol.newMethod( @@ -59,7 +59,7 @@ object Macros { Some(a) } }), - Term.of('{ assert(${ Apply(Apply(Ref(sym3), List(Literal(Constant.Int(3)))), List(Literal(Constant.Int(3)))).asExpr.asInstanceOf[Expr[Int]] } == 3) })) + '{ assert(${ Apply(Apply(Ref(sym3), List(Literal(Constant.Int(3)))), List(Literal(Constant.Int(3)))).asExpr.asInstanceOf[Expr[Int]] } == 3) }.asTerm) // test for recursive references val sym4 : Symbol = Symbol.newMethod( @@ -74,14 +74,14 @@ object Macros { DefDef(sym4, { case List() => { case List(List(x)) => - Some(Term.of('{ + Some('{ if ${ x.asExpr.asInstanceOf[Expr[Int]] } == 0 then 0 - else ${ Apply(Ref(sym4), List(Term.of('{ ${ x.asExpr.asInstanceOf[Expr[Int]] } - 1 }))).asExpr.asInstanceOf[Expr[Int]] } - })) + else ${ Apply(Ref(sym4), List('{ ${ x.asExpr.asInstanceOf[Expr[Int]] } - 1 }.asTerm)).asExpr.asInstanceOf[Expr[Int]] } + }.asTerm) } }), - Term.of('{ assert(${ Apply(Ref(sym4), List(Literal(Constant.Int(4)))).asExpr.asInstanceOf[Expr[Int]] } == 0) })) + '{ assert(${ Apply(Ref(sym4), List(Literal(Constant.Int(4)))).asExpr.asInstanceOf[Expr[Int]] } == 0) }.asTerm) // test for nested functions (one symbol is the other's parent, and we use a Closure) val sym5 : Symbol = Symbol.newMethod( @@ -108,14 +108,14 @@ object Macros { DefDef(sym51, { case List() => { case List(List(xx)) => - Some(Term.of('{ ${ x.asExpr.asInstanceOf[Expr[Int]] } - ${ xx.asExpr.asInstanceOf[Expr[Int]] } })) + Some('{ ${ x.asExpr.asInstanceOf[Expr[Int]] } - ${ xx.asExpr.asInstanceOf[Expr[Int]] } }.asTerm) } })), Closure(Ref(sym51), None)) } } }), - Term.of('{ assert(${ Apply(Ref(sym5), List(Literal(Constant.Int(5)))).asExpr.asInstanceOf[Expr[Int=>Int]] }(4) == 1) })) + '{ assert(${ Apply(Ref(sym5), List(Literal(Constant.Int(5)))).asExpr.asInstanceOf[Expr[Int=>Int]] }(4) == 1) }.asTerm) // test mutually recursive definitions val sym6_1 : Symbol = Symbol.newMethod( @@ -139,12 +139,12 @@ object Macros { case List() => { case List(List(x)) => Some { - Term.of('{ + '{ println(s"sym6_1: ${ ${ x.asExpr.asInstanceOf[Expr[Int]] } }") if ${ x.asExpr.asInstanceOf[Expr[Int]] } == 0 then 0 - else ${ Apply(Ref(sym6_2), List(Term.of('{ ${ x.asExpr.asInstanceOf[Expr[Int]] } - 1 }))).asExpr.asInstanceOf[Expr[Int]] } - }) + else ${ Apply(Ref(sym6_2), List('{ ${ x.asExpr.asInstanceOf[Expr[Int]] } - 1 }.asTerm)).asExpr.asInstanceOf[Expr[Int]] } + }.asTerm } } }), @@ -152,17 +152,17 @@ object Macros { case List() => { case List(List(x)) => Some { - Term.of('{ + '{ println(s"sym6_2: ${ ${ x.asExpr.asInstanceOf[Expr[Int]] } }") if ${ x.asExpr.asInstanceOf[Expr[Int]] } == 0 then 0 - else ${ Apply(Ref(sym6_1), List(Term.of('{ ${ x.asExpr.asInstanceOf[Expr[Int]] } - 1 }))).asExpr.asInstanceOf[Expr[Int]] } - }) + else ${ Apply(Ref(sym6_1), List('{ ${ x.asExpr.asInstanceOf[Expr[Int]] } - 1 }.asTerm)).asExpr.asInstanceOf[Expr[Int]] } + }.asTerm } } }), - Term.of('{ assert(${ Apply(Ref(sym6_2), List(Literal(Constant.Int(6)))).asExpr.asInstanceOf[Expr[Int]] } == 0) })) + '{ assert(${ Apply(Ref(sym6_2), List(Literal(Constant.Int(6)))).asExpr.asInstanceOf[Expr[Int]] } == 0) }.asTerm) // test polymorphic methods by synthesizing an identity method val sym7 : Symbol = Symbol.newMethod( @@ -182,7 +182,7 @@ object Macros { Some(Typed(x, Inferred(t))) } }), - Term.of('{ assert(${ Apply(TypeApply(Ref(sym7), List(Inferred(TypeRepr.of[Int]))), List(Literal(Constant.Int(7)))).asExpr.asInstanceOf[Expr[Int]] } == 7) })) + '{ assert(${ Apply(TypeApply(Ref(sym7), List(Inferred(TypeRepr.of[Int]))), List(Literal(Constant.Int(7)))).asExpr.asInstanceOf[Expr[Int]] } == 7) }.asTerm) Block( sym1Statements ++ @@ -192,7 +192,7 @@ object Macros { sym5Statements ++ sym6Statements ++ sym7Statements ++ - List(Term.of('{ println("Ok") })), + List('{ println("Ok") }.asTerm), Literal(Constant.Unit())).asExpr.asInstanceOf[Expr[Unit]] } } diff --git a/tests/run-macros/tasty-eval/quoted_1.scala b/tests/run-macros/tasty-eval/quoted_1.scala index 1d7f07a06ed0..a6872ae6393c 100644 --- a/tests/run-macros/tasty-eval/quoted_1.scala +++ b/tests/run-macros/tasty-eval/quoted_1.scala @@ -19,7 +19,7 @@ object Macros { override def value(e: Expr[Int])(using Quotes) : Option[Int] = { import quotes.reflect._ - Term.of(e).tpe match { + e.asTerm.tpe match { case pre: TermRef if pre.termSymbol.isValDef => pre.termSymbol.tree match case t: ValDef => diff --git a/tests/run-macros/tasty-extractors-1/quoted_1.scala b/tests/run-macros/tasty-extractors-1/quoted_1.scala index db1656e6474c..b46abc9d20a1 100644 --- a/tests/run-macros/tasty-extractors-1/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-1/quoted_1.scala @@ -8,7 +8,7 @@ object Macros { def impl[T](x: Expr[T])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(x) + val tree = x.asTerm val treeStr = Expr(tree.show(using Printer.TreeStructure)) val treeTpeStr = Expr(tree.tpe.show(using Printer.TypeReprStructure)) diff --git a/tests/run-macros/tasty-extractors-2/quoted_1.scala b/tests/run-macros/tasty-extractors-2/quoted_1.scala index 822047e1f70e..83e401e09cf7 100644 --- a/tests/run-macros/tasty-extractors-2/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-2/quoted_1.scala @@ -8,7 +8,7 @@ object Macros { def impl[T](x: Expr[T])(using q: Quotes) : Expr[Unit] = { import q.reflect._ - val tree = Term.of(x) + val tree = x.asTerm val treeStr = Expr(tree.show(using Printer.TreeStructure)) val treeTpeStr = Expr(tree.tpe.show(using Printer.TypeReprStructure)) diff --git a/tests/run-macros/tasty-extractors-3/quoted_1.scala b/tests/run-macros/tasty-extractors-3/quoted_1.scala index d15254cc27f1..6f20cb701bd1 100644 --- a/tests/run-macros/tasty-extractors-3/quoted_1.scala +++ b/tests/run-macros/tasty-extractors-3/quoted_1.scala @@ -25,7 +25,7 @@ object Macros { } } - val tree = Term.of(x) + val tree = x.asTerm traverser.traverseTree(tree)(Symbol.spliceOwner) '{print(${Expr(buff.result())})} } diff --git a/tests/run-macros/tasty-interpolation-1/Macro.scala b/tests/run-macros/tasty-interpolation-1/Macro.scala index e8be14e75d97..349983a4c629 100644 --- a/tests/run-macros/tasty-interpolation-1/Macro.scala +++ b/tests/run-macros/tasty-interpolation-1/Macro.scala @@ -56,7 +56,7 @@ abstract class MacroStringInterpolator[T] { protected def getStaticStringContext(strCtxExpr: Expr[StringContext])(using Quotes) : StringContext = { import quotes.reflect._ - Term.of(strCtxExpr).underlyingArgument match { + strCtxExpr.asTerm.underlyingArgument match { case Select(Typed(Apply(_, List(Apply(_, List(Typed(Repeated(strCtxArgTrees, _), Inferred()))))), _), _) => val strCtxArgs = strCtxArgTrees.map { case Literal(Constant.String(str)) => str @@ -70,7 +70,7 @@ abstract class MacroStringInterpolator[T] { protected def getArgsList(argsExpr: Expr[Seq[Any]])(using Quotes) : List[Expr[Any]] = { import quotes.reflect._ - Term.of(argsExpr).underlyingArgument match { + argsExpr.asTerm.underlyingArgument match { case Typed(Repeated(args, _), _) => args.map(_.asExpr) case tree => throw new NotStaticlyKnownError("Expected statically known argument list", tree.asExpr) } diff --git a/tests/run-macros/tasty-macro-assert/quoted_1.scala b/tests/run-macros/tasty-macro-assert/quoted_1.scala index 3ec8cc575299..da2afd1126b6 100644 --- a/tests/run-macros/tasty-macro-assert/quoted_1.scala +++ b/tests/run-macros/tasty-macro-assert/quoted_1.scala @@ -15,7 +15,7 @@ object Asserts { def impl(cond: Expr[Boolean])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val tree = Term.of(cond) + val tree = cond.asTerm def isOps(tpe: TypeRepr): Boolean = tpe match { case tpe: TermRef => tpe.termSymbol.isDefDef && tpe.name == "Ops"// TODO check that the parent is Asserts diff --git a/tests/run-macros/tasty-macro-const/quoted_1.scala b/tests/run-macros/tasty-macro-const/quoted_1.scala index 4a5f3e26f83d..0346248be16c 100644 --- a/tests/run-macros/tasty-macro-const/quoted_1.scala +++ b/tests/run-macros/tasty-macro-const/quoted_1.scala @@ -6,7 +6,7 @@ object Macros { def natConstImpl(x: Expr[Int])(using Quotes) : Expr[Int] = { import quotes.reflect._ - val xTree: Term = Term.of(x) + val xTree: Term = x.asTerm xTree match { case Inlined(_, _, Literal(Constant.Int(n))) => if (n <= 0) { diff --git a/tests/run-macros/tasty-macro-positions/quoted_1.scala b/tests/run-macros/tasty-macro-positions/quoted_1.scala index 9e20acbbf1c9..e0f7f02e9760 100644 --- a/tests/run-macros/tasty-macro-positions/quoted_1.scala +++ b/tests/run-macros/tasty-macro-positions/quoted_1.scala @@ -10,8 +10,8 @@ object Macros { def impl(x: Expr[Any])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val pos = posStr(Term.of(x).underlyingArgument.pos) - val code = Term.of(x).underlyingArgument.show + val pos = posStr(x.asTerm.underlyingArgument.pos) + val code = x.asTerm.underlyingArgument.show '{ println($pos) println(${Expr(code)}) diff --git a/tests/run-macros/tasty-original-source/Macros_1.scala b/tests/run-macros/tasty-original-source/Macros_1.scala index 71bbb6c2dd80..fc733e3037ae 100644 --- a/tests/run-macros/tasty-original-source/Macros_1.scala +++ b/tests/run-macros/tasty-original-source/Macros_1.scala @@ -6,7 +6,7 @@ object Macros { private def impl(arg: Expr[Any])(using Quotes) : Expr[(String, Any)] = { import quotes.reflect._ - val source = Expr(Term.of(arg).underlyingArgument.pos.sourceCode.get.toString) + val source = Expr(arg.asTerm.underlyingArgument.pos.sourceCode.get.toString) '{Tuple2($source, $arg)} } diff --git a/tests/run-macros/tasty-overload-secondargs/Macro_1.scala b/tests/run-macros/tasty-overload-secondargs/Macro_1.scala index c7eea6624040..8a5f805d1f0f 100644 --- a/tests/run-macros/tasty-overload-secondargs/Macro_1.scala +++ b/tests/run-macros/tasty-overload-secondargs/Macro_1.scala @@ -21,14 +21,14 @@ object Macro: mThenImpl[A,B,PartialFunction[A,B],Option[B]]('x) } - def mThenImpl[A:Type, B:Type, S<:(A=>B) :Type, R:Type](x:Expr[S])(using Quotes):Expr[R]= + def mThenImpl[A:Type, B:Type, S<:(A=>B) :Type, R:Type](x:Expr[S])(using Quotes):Expr[R] = import quotes.reflect._ - val fun = Term.of('{X}) + val fun = '{X}.asTerm val returnType = TypeRepr.of[(S) => ?] val firstPart = Select.overloaded(fun,"andThen", List(TypeIdent(defn.IntClass).tpe, TypeIdent(defn.IntClass).tpe), List(Literal(Constant.Int(1))), TypeRepr.of[(S) => R] ) - val r = Apply(firstPart,List(Term.of(x))) + val r = Apply(firstPart,List(x.asTerm)) r.asExprOf[R] diff --git a/tests/run-macros/tasty-seal-method/quoted_1.scala b/tests/run-macros/tasty-seal-method/quoted_1.scala index 15c8bdd97513..735270480998 100644 --- a/tests/run-macros/tasty-seal-method/quoted_1.scala +++ b/tests/run-macros/tasty-seal-method/quoted_1.scala @@ -9,7 +9,7 @@ object Asserts { def zeroLastArgsImpl(x: Expr[Int])(using Quotes) : Expr[Int] = { import quotes.reflect._ // For simplicity assumes that all parameters are Int and parameter lists have no more than 3 elements - Term.of(x).underlyingArgument match { + x.asTerm.underlyingArgument match { case Apply(fn, args) => fn.tpe.widen match { case _: MethodType => @@ -35,15 +35,15 @@ object Asserts { case Apply(fn, args) => val pre = rec(fn) args.size match { - case 0 => Term.of(Expr.betaReduce('{ ${pre.etaExpand(Symbol.spliceOwner).asExprOf[() => Any]}() })) - case 1 => Term.of(Expr.betaReduce('{ ${pre.etaExpand(Symbol.spliceOwner).asExprOf[Int => Any]}(0) })) - case 2 => Term.of(Expr.betaReduce('{ ${pre.etaExpand(Symbol.spliceOwner).asExprOf[(Int, Int) => Any]}(0, 0) })) - case 3 => Term.of(Expr.betaReduce('{ ${pre.etaExpand(Symbol.spliceOwner).asExprOf[(Int, Int, Int) => Any]}(0, 0, 0) })) + case 0 => Expr.betaReduce('{ ${pre.etaExpand(Symbol.spliceOwner).asExprOf[() => Any]}() }).asTerm + case 1 => Expr.betaReduce('{ ${pre.etaExpand(Symbol.spliceOwner).asExprOf[Int => Any]}(0) }).asTerm + case 2 => Expr.betaReduce('{ ${pre.etaExpand(Symbol.spliceOwner).asExprOf[(Int, Int) => Any]}(0, 0) }).asTerm + case 3 => Expr.betaReduce('{ ${pre.etaExpand(Symbol.spliceOwner).asExprOf[(Int, Int, Int) => Any]}(0, 0, 0) }).asTerm } case _ => term } - rec(Term.of(x).underlyingArgument).asExprOf[Int] + rec(x.asTerm.underlyingArgument).asExprOf[Int] } } diff --git a/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala b/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala index 509b55acb397..1c5d392b1e41 100644 --- a/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala +++ b/tests/run-macros/tasty-string-interpolation-reporter-test/Macros_1.scala @@ -24,7 +24,7 @@ object Macro { val reporter = new Reporter { def errorOnPart(msg: String, partIdx: Int): Unit = { import quotes.reflect._ - report.error(msg, Term.of(parts(partIdx)).pos) + report.error(msg, parts(partIdx).asTerm.pos) } } fooCore(parts, args, reporter) @@ -38,7 +38,7 @@ object Macro { val reporter = new Reporter { def errorOnPart(msg: String, partIdx: Int): Unit = { import quotes.reflect._ - val pos = Term.of(parts(partIdx)).pos + val pos = parts(partIdx).asTerm.pos errors += '{ Tuple4(${Expr(partIdx)}, ${Expr(pos.start)}, ${Expr(pos.end)}, ${Expr(msg)}) } } } diff --git a/tests/run-macros/tasty-tree-map/quoted_1.scala b/tests/run-macros/tasty-tree-map/quoted_1.scala index 7a69ef874370..a4363f60b599 100644 --- a/tests/run-macros/tasty-tree-map/quoted_1.scala +++ b/tests/run-macros/tasty-tree-map/quoted_1.scala @@ -7,6 +7,6 @@ object MacrosImpl: def impl[T: Type](x: Expr[T])(using Quotes) : Expr[T] = { import quotes.reflect._ val identityMap = new TreeMap { } - val transformed = identityMap.transformTerm(Term.of(x))(Symbol.spliceOwner).asExprOf[T] + val transformed = identityMap.transformTerm(x.asTerm)(Symbol.spliceOwner).asExprOf[T] transformed } diff --git a/tests/run-macros/tasty-unsafe-let/quoted_1.scala b/tests/run-macros/tasty-unsafe-let/quoted_1.scala index cd93665a0460..fe8b3c7b86d2 100644 --- a/tests/run-macros/tasty-unsafe-let/quoted_1.scala +++ b/tests/run-macros/tasty-unsafe-let/quoted_1.scala @@ -8,11 +8,11 @@ object Macros { private def impl[T: Type](rhs: Expr[T], body: Expr[T => Unit])(using Quotes) : Expr[Unit] = { import quotes.reflect._ - val rhsTerm = Term.of(rhs) + val rhsTerm = rhs.asTerm import quotes.reflect._ ValDef.let(Symbol.spliceOwner, rhsTerm) { rhsId => - Term.of(Expr.betaReduce('{$body(${rhsId.asExpr.asInstanceOf[Expr[T]]})})) // Dangerous uncheked cast! + Expr.betaReduce('{$body(${rhsId.asExpr.asInstanceOf[Expr[T]]})}).asTerm // Dangerous uncheked cast! }.asExprOf[Unit] } diff --git a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala index 8b7a888c084a..d72697054e49 100644 --- a/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-1/XmlQuote_1.scala @@ -41,7 +41,7 @@ object XmlQuote { tree.symbol.fullName == "scala.StringContext$.apply" // XmlQuote.SCOps(StringContext.apply([p0, ...]: String*) - val parts = Term.of(receiver).underlyingArgument match { + val parts = receiver.asTerm.underlyingArgument match { case Apply(conv, List(Apply(fun, List(Typed(Repeated(values, _), _))))) if isSCOpsConversion(conv) && isStringContextApply(fun) && @@ -53,7 +53,7 @@ object XmlQuote { } // [a0, ...]: Any* - val Typed(Repeated(args0, _), _) = Term.of(args).underlyingArgument + val Typed(Repeated(args0, _), _) = args.asTerm.underlyingArgument val string = parts.mkString("??") '{new Xml(${Expr(string)}, ${liftListOfAny(args0)})} diff --git a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala index eac958ce25bf..aa62800bdabd 100644 --- a/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala +++ b/tests/run-macros/xml-interpolation-2/XmlQuote_1.scala @@ -36,7 +36,7 @@ object XmlQuote { } // XmlQuote.SCOps(StringContext.apply([p0, ...]: String*) - val parts: List[String] = stripTyped(Term.of(receiver).underlying) match { + val parts: List[String] = stripTyped(receiver.asTerm.underlying) match { case Apply(conv, List(ctx1)) if isSCOpsConversion(conv) => ctx1 match { case Apply(fun, List(Typed(Repeated(values, _), _))) if isStringContextApply(fun) => @@ -56,7 +56,7 @@ object XmlQuote { } // [a0, ...]: Any* - val args2: Expr[List[Any]] = Term.of(args).underlyingArgument match { + val args2: Expr[List[Any]] = args.asTerm.underlyingArgument match { case Typed(Repeated(args0, _), _) => // statically known args, make list directly Expr.ofList(args0.map(_.asExpr)) case _ =>