@@ -48,17 +48,17 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
4848
4949 extension [T ](self : scala.quoted.Expr [T ]):
5050 def show : String =
51- reflect.Printer .TreeCode .show(reflect.Term .of (self))
51+ reflect.Printer .TreeCode .show(reflect.asTerm (self))
5252
5353 def matches (that : scala.quoted.Expr [Any ]): Boolean =
54- treeMatch(reflect.Term .of (self), reflect.Term .of (that)).nonEmpty
54+ treeMatch(reflect.asTerm (self), reflect.asTerm (that)).nonEmpty
5555
5656 end extension
5757
5858 extension [X ](self : scala.quoted.Expr [Any ]):
5959 /** Checks is the `quoted.Expr[?]` is valid expression of type `X` */
6060 def isExprOf (using scala.quoted.Type [X ]): Boolean =
61- reflect.TypeReprMethods .<:< (reflect.Term .of (self).tpe)(reflect.TypeRepr .of[X ])
61+ reflect.TypeReprMethods .<:< (reflect.asTerm (self).tpe)(reflect.TypeRepr .of[X ])
6262
6363 /** Convert this to an `quoted.Expr[X]` if this expression is a valid expression of type `X` or throws */
6464 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
6767 else
6868 throw Exception (
6969 s """ Expr cast exception: ${self.show}
70- |of type: ${reflect.Printer .TypeReprCode .show(reflect.Term .of (self).tpe)}
70+ |of type: ${reflect.Printer .TypeReprCode .show(reflect.asTerm (self).tpe)}
7171 |did not conform to type: ${reflect.Printer .TypeReprCode .show(reflect.TypeRepr .of[X ])}
7272 | """ .stripMargin
7373 )
@@ -76,11 +76,16 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
7676
7777 object reflect extends reflectModule :
7878
79+ extension (expr : Expr [Any ]):
80+ def asTerm : Term =
81+ val exprImpl = expr.asInstanceOf [ExprImpl ]
82+ exprImpl.checkScopeId(QuotesImpl .this .hashCode)
83+ exprImpl.tree
84+ end extension
85+
7986 type Tree = tpd.Tree
8087
81- object Tree extends TreeModule :
82- def of (expr : Expr [Any ]): Tree = Term .of(expr)
83- end Tree
88+ object Tree extends TreeModule
8489
8590 given TreeMethods : TreeMethods with
8691 extension (self : Tree ):
@@ -340,11 +345,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
340345 end TermTypeTest
341346
342347 object Term extends TermModule :
343- def of (expr : Expr [Any ]): Term =
344- val exprImpl = expr.asInstanceOf [ExprImpl ]
345- exprImpl.checkScopeId(QuotesImpl .this .hashCode)
346- exprImpl.tree
347-
348348 def betaReduce (tree : Term ): Option [Term ] =
349349 tree match
350350 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
25882588 dotc.report.error(msg, Position .ofMacroExpansion)
25892589
25902590 def error (msg : String , expr : Expr [Any ]): Unit =
2591- dotc.report.error(msg, Term .of (expr).pos)
2591+ dotc.report.error(msg, asTerm (expr).pos)
25922592
25932593 def error (msg : String , pos : Position ): Unit =
25942594 dotc.report.error(msg, pos)
@@ -2609,7 +2609,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
26092609 dotc.report.warning(msg, Position .ofMacroExpansion)
26102610
26112611 def warning (msg : String , expr : Expr [Any ]): Unit =
2612- dotc.report.warning(msg, Term .of (expr).pos)
2612+ dotc.report.warning(msg, asTerm (expr).pos)
26132613
26142614 def warning (msg : String , pos : Position ): Unit =
26152615 dotc.report.warning(msg, pos)
@@ -2716,8 +2716,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
27162716
27172717 object ExprMatch extends ExprMatchModule :
27182718 def unapply [TypeBindings <: Tuple , Tup <: Tuple ](scrutinee : scala.quoted.Expr [Any ])(using pattern : scala.quoted.Expr [Any ]): Option [Tup ] =
2719- val scrutineeTree = reflect.Term .of (scrutinee)
2720- val patternTree = reflect.Term .of (pattern)
2719+ val scrutineeTree = reflect.asTerm (scrutinee)
2720+ val patternTree = reflect.asTerm (pattern)
27212721 treeMatch(scrutineeTree, patternTree).asInstanceOf [Option [Tup ]]
27222722 end ExprMatch
27232723
0 commit comments