Skip to content

Commit 175c8d7

Browse files
committed
Fix Select matching as an Expr
1 parent 642498c commit 175c8d7

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

library/src-bootstrapped/scala/quoted/util/ExprMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 {

tests/run-macros/expr-map-2.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Foo(2)
2+
4
3+
4
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

0 commit comments

Comments
 (0)