Skip to content

Commit 17bd00d

Browse files
committed
Cover nested method type
1 parent 74bef21 commit 17bd00d

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,16 @@ object QuoteMatcher {
481481
/*
482482
* PR-17567 Remaining TODOs
483483
* * [ ] Implicit / Contextual parameters
484-
* * [ ] Nested Method Types
484+
* * [x] Nested Method Types
485485
* * [ ] Erased Types
486486
*/
487487
def adaptTypes(tpe: Type)(using Context): Type =
488488
new Types.TypeMap {
489489
def apply(tp: Types.Type): Types.Type = tp match
490490
case tp: MethodType => {
491-
return defn.FunctionOf(tp.paramInfos, tp.resultType)
491+
val paramInfos = tp.paramInfos map adaptTypes
492+
val resultType = adaptTypes(tp.resultType)
493+
return defn.FunctionOf(paramInfos, resultType)
492494
}
493495
case _ => mapOver(tp)
494496
}.apply(tpe)
@@ -523,16 +525,28 @@ object QuoteMatcher {
523525
* because the type of `g` is `Int => Int` due to eta expansion.
524526
*
525527
* Remaining TODOs from issue-17105
526-
* * [ ] cover the case of nested method call
528+
* * [x] cover the case of nested method call
527529
* * [ ] contextual params?
528530
* * [ ] erasure types?
531+
* * [ ] eta-expand only HOAS param methods
529532
*/
530533
case Apply(methId: Ident, args) =>
531534
val fnId = env.get(tree.symbol).flatMap(argsMap.get).getOrElse(tree)
532535
ctx.typer.typed(
533536
untpd.Apply(
534537
untpd.Select(untpd.TypedSplice(fnId), nme.apply),
535538
args.map(untpd.TypedSplice(_))))
539+
case Apply(fun, args) =>
540+
val tfun = transform(fun)
541+
val targs = transform(args)
542+
tfun.tpe match
543+
// TODO issue-17105: Is this pattern appropriate for methods?
544+
case tp: MethodOrPoly => cpy.Apply(tree)(tfun, targs)
545+
// TODO issue-17105: Appropriate pattern for function (appliable?) types?
546+
case _ => ctx.typer.typed(
547+
untpd.Apply(
548+
untpd.Select(untpd.TypedSplice(tfun), nme.apply),
549+
args map (untpd.TypedSplice(_))))
536550
case tree: Ident => env.get(tree.symbol).flatMap(argsMap.get).getOrElse(tree)
537551
case tree => super.transform(tree)
538552
}.transform(tree)

tests/run-macros/i17105.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
test single: (1st case arg1) outside
2-
test curried: (2nd case arg1, arg2) outside
1+
case single: (1st case 1st) outside
2+
case curried: (2nd case 1st, 2nd) outside

tests/run-macros/i17105/Test_2.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@main def Test: Unit =
2-
println("test single: " + testExpr { def f(x: String) = "placeholder" + x; f("arg1") + " outside" })
3-
println("test curried: " + testExpr { def f(x: String)(y: String) = "placeholder" + x; f("arg1")("args2") + " outside" })
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" })

0 commit comments

Comments
 (0)