Skip to content

Commit 0cb392f

Browse files
committed
Use extension method in TASTy Refection
1 parent cd12e32 commit 0cb392f

File tree

118 files changed

+199
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+199
-200
lines changed

docs/docs/reference/metaprogramming/tasty-reflect.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ import scala.quoted._
2929
inline def natConst(x: => Int): Int = ${natConstImpl('{x})}
3030

3131
def natConstImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[Int] = {
32-
import qctx.tasty._
32+
import qctx.tasty.{_, given}
3333
...
3434
}
3535
```
3636

3737
### Sealing and Unsealing
3838

39-
`import qctx.tasty._` will provide an `unseal` extension method on `quoted.Expr`
39+
`import qctx.tasty.{_, given}` will provide an `unseal` extension method on `quoted.Expr`
4040
and `quoted.Type` which returns a `qctx.tasty.Term` that represents the tree of
4141
the expression and `qctx.tasty.TypeTree` that represents the tree of the type
4242
respectively. It will also import all extractors and methods on TASTy Reflect
4343
trees. For example the `Literal(_)` extractor used below.
4444

4545
```scala
4646
def natConstImpl(x: Expr[Int])(given qctx: QuoteContext): Expr[Int] = {
47-
import qctx.tasty._
47+
import qctx.tasty.{_, given}
4848
val xTree: Term = x.unseal
4949
xTree match {
5050
case Inlined(_, _, Literal(Constant(n: Int))) =>
@@ -81,7 +81,7 @@ operation expression passed while calling the `macro` below.
8181
inline def macro(param: => Boolean): Unit = ${ macroImpl('param) }
8282

8383
def macroImpl(param: Expr[Boolean])(given qctx: QuoteContext): Expr[Unit] = {
84-
import qctx.tasty._
84+
import qctx.tasty.{_, given}
8585
import util._
8686

8787
param.unseal.underlyingArgument match {
@@ -103,7 +103,7 @@ point.
103103

104104
```scala
105105
def macroImpl()(qctx: QuoteContext): Expr[Unit] = {
106-
import qctx.tasty._
106+
import qctx.tasty.{_, given}
107107
val pos = rootPosition
108108

109109
val path = pos.sourceFile.jpath.toString

library/src-bootstrapped/dotty/internal/StringContextMacro.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ object StringContextMacro {
8282
* quotes an error if the given Expr does not contain a list of arguments
8383
*/
8484
def getArgsExprs(argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Option[List[Expr[Any]]] = {
85-
import qctx.tasty._
85+
import qctx.tasty.{_, given}
8686
argsExpr.unseal.underlyingArgument match {
8787
case Typed(Repeated(args, _), _) =>
8888
Some(args.map(_.seal))
@@ -99,7 +99,7 @@ object StringContextMacro {
9999
* @return the Expr containing the formatted and interpolated String or an error/warning if the parameters are not correct
100100
*/
101101
private def interpolate(strCtxExpr: Expr[StringContext], argsExpr: Expr[Seq[Any]])(given qctx: QuoteContext): Expr[String] = {
102-
import qctx.tasty._
102+
import qctx.tasty.{_, given}
103103
val sourceFile = strCtxExpr.unseal.pos.sourceFile
104104

105105
val (partsExpr, parts) = getPartsExprs(strCtxExpr) match {
@@ -165,7 +165,7 @@ object StringContextMacro {
165165
* @return the Expr containing the formatted and interpolated String or an error/warning report if the parameters are not correct
166166
*/
167167
def interpolate(parts0 : List[String], args : List[Expr[Any]], argsExpr: Expr[Seq[Any]], reporter : Reporter)(given qctx: QuoteContext) : Expr[String] = {
168-
import qctx.tasty._
168+
import qctx.tasty.{_, given}
169169

170170
/** Checks if the number of arguments are the same as the number of formatting strings
171171
*

library/src-bootstrapped/scala/quoted/Liftable.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ object Liftable {
3232
private class PrimitiveLiftable[T <: Unit | Null | Int | Boolean | Byte | Short | Int | Long | Float | Double | Char | String] extends Liftable[T] {
3333
/** Lift a primitive value `n` into `'{ n }` */
3434
def toExpr(x: T) = (given qctx) => {
35-
import qctx.tasty._
35+
import qctx.tasty.{_, given}
3636
Literal(Constant(x)).seal.asInstanceOf[Expr[T]]
3737
}
3838
}
3939

4040
given ClassIsLiftable[T] : Liftable[Class[T]] = new Liftable[Class[T]] {
4141
/** Lift a `Class[T]` into `'{ classOf[T] }` */
4242
def toExpr(x: Class[T]) = (given qctx) => {
43-
import qctx.tasty._
43+
import qctx.tasty.{_, given}
4444
Ref(defn.Predef_classOf).appliedToType(Type(x)).seal.asInstanceOf[Expr[Class[T]]]
4545
}
4646
}

library/src/scala/internal/quoted/Expr.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object Expr {
2727
*/
2828
def unapply[TypeBindings <: Tuple, Tup <: Tuple](scrutineeExpr: Expr[_])(implicit patternExpr: Expr[_],
2929
hasTypeSplices: Boolean, qctx: QuoteContext): Option[Tup] = {
30-
import qctx.tasty._
30+
import qctx.tasty.{_, given}
3131
new Matcher.QuoteMatcher[qctx.type].termMatch(scrutineeExpr.unseal, patternExpr.unseal, hasTypeSplices).asInstanceOf[Option[Tup]]
3232
}
3333

0 commit comments

Comments
 (0)