Skip to content

Commit c5d776f

Browse files
committed
Add a test case
1 parent b6a1310 commit c5d776f

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,13 @@ class QuoteMatcher(debug: Boolean) {
644644
val meth = newAnonFun(ctx.owner, methTpe)
645645

646646
def bodyFn(lambdaArgss: List[List[Tree]]): Tree = {
647-
val typeArgsMap = ptTypeVarSymbols.zip(lambdaArgss.head.map(_.tpe)).toMap
648-
val argsMap = argIds.view.map(_.symbol).zip(lambdaArgss.tail.head).toMap
647+
val (typeParams, params) = if typeArgs.isEmpty then
648+
(List.empty, lambdaArgss.head)
649+
else
650+
(lambdaArgss.head.map(_.tpe), lambdaArgss.tail.head)
651+
652+
val typeArgsMap = ptTypeVarSymbols.zip(typeParams).toMap
653+
val argsMap = argIds.view.map(_.symbol).zip(params).toMap
649654

650655
val body = new TreeTypeMap(
651656
typeMap = if typeArgs.isEmpty then IdentityTypeMap
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
not matched
21
case 2 matched => 5
2+
case 3 matched => truthy
3+
case 4 matched => truthy

tests/run-macros/quote-match-poly-function/Macro_1.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ def testExprImpl1(body: Expr[Any])(using Quotes): Expr[String] =
77
'{ "case 2 matched => " + $b(2, 3) }
88
case '{ [A] => (x : A, y : A) => $b[A](x, y) : A } =>
99
'{ "case 3 matched => " + $b[String]("truthy", "falsy") }
10+
case '{ [A] => (x : A, y : A) => $b[A](x, y) : (A, A) } =>
11+
'{ "case 4 matched => " + $b[String]("truthy", "falsy")._2 }
1012
case _ => Expr("not matched")
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@main def Test: Unit =
2-
println(testExpr([B] => (x : B, y : B) => x)) // Should match case 3
32
println(testExpr([B] => (x : Int, y : Int) => x + y)) // Should match case 2
3+
println(testExpr([B] => (x : B, y : B) => x)) // Should match case 3
4+
println(testExpr([B] => (x : B, y : B) => (y, x))) // Should match case 4

0 commit comments

Comments
 (0)