Skip to content

Commit 2b72c18

Browse files
Merge pull request #10519 from dotty-staging/move-quotes-as-last-parameter
Move `Quotes` as last parameter in `ExprMap.transform`
2 parents a3fcb15 + bddeef0 commit 2b72c18

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

library/src/scala/quoted/ExprMap.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package scala.quoted
33
trait ExprMap:
44

55
/** Map an expression `e` with a type `T` */
6-
def transform[T](e: Expr[T])(using Quotes, Type[T]): Expr[T]
6+
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T]
77

88
/** Map subexpressions an expression `e` with a type `T` */
9-
def transformChildren[T](e: Expr[T])(using Quotes, Type[T]): Expr[T] = {
9+
def transformChildren[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = {
1010
import quotes.reflect._
1111
final class MapChildren() {
1212

@@ -99,10 +99,13 @@ trait ExprMap:
9999
case _: Inlined =>
100100
transformTermChildren(tree, tpe)(owner)
101101
case _ if tree.isExpr =>
102+
// WARNING: Never do a cast like this in user code (accepable within the stdlib).
103+
// In theory we should use `tree.asExpr match { case '{ $expr: t } => Term.of(transform(expr)) }`
104+
// This is to avoid conflicts when re-boostrapping the library.
102105
type X
103106
val expr = tree.asExpr.asInstanceOf[Expr[X]]
104107
val t = tpe.asType.asInstanceOf[Type[X]]
105-
val transformedExpr = transform(expr)(using quotes, t)
108+
val transformedExpr = transform(expr)(using t)
106109
Term.of(transformedExpr)
107110
case _ =>
108111
transformTermChildren(tree, tpe)(owner)

tests/run-macros/expr-map-1/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private def stringRewriter(e: Expr[Any])(using Quotes): Expr[Any] =
88

99
private object StringRewriter extends ExprMap {
1010

11-
def transform[T](e: Expr[T])(using Quotes, Type[T]): Expr[T] = e match
11+
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = e match
1212
case Const(s: String) =>
1313
Expr(s.reverse) match
1414
case '{ $x: T } => x

tests/run-macros/expr-map-2/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private def stringRewriter(e: Expr[Any])(using Quotes): Expr[Any] =
88

99
private object StringRewriter extends ExprMap {
1010

11-
def transform[T](e: Expr[T])(using Quotes, Type[T]): Expr[T] = e match
11+
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = e match
1212
case '{ ($x: Foo).x } =>
1313
'{ new Foo(4).x } match
1414
case '{ $e: T } => e

tests/run-macros/flops-rewrite-2/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private object Rewriter {
6464
}
6565

6666
private class Rewriter(preTransform: List[Transformation[_]] = Nil, postTransform: List[Transformation[_]] = Nil, fixPoint: Boolean) extends ExprMap {
67-
def transform[T](e: Expr[T])(using Quotes, Type[T]): Expr[T] = {
67+
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = {
6868
val e2 = preTransform.foldLeft(e)((ei, transform) => transform(ei))
6969
val e3 = transformChildren(e2)
7070
val e4 = postTransform.foldLeft(e3)((ei, transform) => transform(ei))

tests/run-macros/flops-rewrite-3/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private class Rewriter private (preTransform: List[Transformation] = Nil, postTr
101101
def withPost(transform: Transformation): Rewriter =
102102
new Rewriter(preTransform, transform :: postTransform, fixPoint)
103103

104-
def transform[T](e: Expr[T])(using Quotes, Type[T]): Expr[T] = {
104+
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = {
105105
val e2 = preTransform.foldLeft(e)((ei, transform) => transform(ei))
106106
val e3 = transformChildren(e2)
107107
val e4 = postTransform.foldLeft(e3)((ei, transform) => transform(ei))

tests/run-macros/flops-rewrite/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private object Rewriter {
2929
}
3030

3131
private class Rewriter(preTransform: Expr[Any] => Expr[Any], postTransform: Expr[Any] => Expr[Any], fixPoint: Boolean) extends ExprMap {
32-
def transform[T](e: Expr[T])(using Quotes, Type[T]): Expr[T] = {
32+
def transform[T](e: Expr[T])(using Type[T])(using Quotes): Expr[T] = {
3333
val e2 = checkedTransform(e, preTransform)
3434
val e3 = transformChildren(e2)
3535
val e4 = checkedTransform(e3, postTransform)

0 commit comments

Comments
 (0)