Skip to content

Commit 0cffa8f

Browse files
committed
Fix a bug where method call with methods from outer scope get adapted
1 parent 5a8aa50 commit 0cffa8f

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,15 @@ object QuoteMatcher {
528528
* * [x] cover the case of nested method call
529529
* * [ ] contextual params?
530530
* * [ ] erasure types?
531-
* * [ ] eta-expand only HOAS param methods
531+
* * [x] eta-expand only HOAS param methods
532532
*/
533533
case Apply(methId: Ident, args) =>
534-
val fnId = env.get(tree.symbol).flatMap(argsMap.get).getOrElse(tree)
535-
ctx.typer.typed(
536-
untpd.Apply(
537-
untpd.Select(untpd.TypedSplice(fnId), nme.apply),
538-
args.map(untpd.TypedSplice(_))))
534+
env.get(tree.symbol).flatMap(argsMap.get)
535+
.map(fnId => ctx.typer.typed(
536+
untpd.Apply(
537+
untpd.Select(untpd.TypedSplice(fnId), nme.apply),
538+
args.map(untpd.TypedSplice(_)))))
539+
.getOrElse(super.transform(tree))
539540
case Apply(fun, args) =>
540541
val tfun = transform(fun)
541542
val targs = transform(args)

tests/run-macros/i17105.check

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
case single: (1st case 1st) outside
2-
case curried: (2nd case 1st, 2nd) outside
1+
case single: [1st case] arg1 outside
2+
case curried: [2nd case] arg1, arg2 outside
3+
case methods from outer scope: [1st case] arg1 outer-method

tests/run-macros/i17105/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ inline def testExpr(inline body: Any) = ${ testExprImpl('body) }
44
def testExprImpl(body: Expr[Any])(using Quotes): Expr[String] =
55
body match
66
case '{ def g(y: String) = "placeholder" + y; $a(g): String } =>
7-
'{ $a((z: String) => s"(1st case ${z})") }
7+
'{ $a((z: String) => s"[1st case] ${z}") }
88
case '{ def g(y: String)(z: String) = "placeholder" + y; $a(g): String } =>
9-
'{ $a((z1: String) => (z2: String) => s"(2nd case ${z1}, ${z2})") }
9+
'{ $a((z1: String) => (z2: String) => s"[2nd case] ${z1}, ${z2}") }
1010
case _ => Expr("not matched")
1111

1212
// TODO issue-17105: Clean this up if not neccessary

tests/run-macros/i17105/Test_2.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@main def Test: Unit =
2-
println("case single: " + testExpr { def f(x: String) = "placeholder" + x; f("1st") + " outside" })
3-
println("case curried: " + testExpr { def f(x: String)(y: String) = "placeholder" + x; f("1st")("2nd") + " outside" })
4-
def outer() = "outside-method"
5-
println("case methods from outer scope " + testExpr { def f(x: String) = "placeholder" + x; f("1st") + outer() })
2+
println("case single: " + testExpr { def f(x: String) = "placeholder" + x; f("arg1") + " outside" })
3+
println("case curried: " + testExpr { def f(x: String)(y: String) = "placeholder" + x; f("arg1")("arg2") + " outside" })
4+
def outer() = " outer-method"
5+
println("case methods from outer scope: " + testExpr { def f(x: String) = "placeholder" + x; f("arg1") + outer() })

0 commit comments

Comments
 (0)