File tree Expand file tree Collapse file tree 4 files changed +36
-1
lines changed
library/src-bootstrapped/scala/quoted/util Expand file tree Collapse file tree 4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ trait ExprMap {
102102 tree match {
103103 case _ : Closure =>
104104 tree
105- case _ : Inlined | _ : Select =>
105+ case _ : Inlined =>
106106 transformTermChildren(tree, tpe)
107107 case _ =>
108108 tree.tpe.widen match {
Original file line number Diff line number Diff line change 1+ Foo(2)
2+ 4
3+ 4
Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+ import scala .quoted .matching ._
3+
4+ inline def rewrite [T ](x : => Any ): Any = $ { stringRewriter(' x ) }
5+
6+ private def stringRewriter (e : Expr [Any ])(given QuoteContext ): Expr [Any ] =
7+ StringRewriter .transform(e)
8+
9+ private object StringRewriter extends util.ExprMap {
10+
11+ def transform [T ](e : Expr [T ])(given QuoteContext , Type [T ]): Expr [T ] = e match
12+ case ' { ($x : Foo ).x } =>
13+ ' { new Foo (4 ).x } match case ' { $e : T } => e
14+ case _ =>
15+ transformChildren(e)
16+
17+ }
18+
19+ case class Foo (x : Int )
Original file line number Diff line number Diff line change 1+ object Test {
2+
3+ def main (args : Array [String ]): Unit = {
4+ println(rewrite(new Foo (2 )))
5+ println(rewrite(new Foo (2 ).x))
6+
7+ rewrite {
8+ val foo = new Foo (2 )
9+ println(foo.x)
10+ }
11+
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments