From f180e03aed9a4965a3e96b7baa141f3c455fc0f8 Mon Sep 17 00:00:00 2001 From: Yuito Murase Date: Mon, 7 Aug 2023 22:02:44 +0900 Subject: [PATCH] Add a test case --- .../src/scala/quoted/runtime/impl/QuoteMatcher.scala | 9 +++++++-- tests/run-macros/quote-match-poly-function.check | 3 ++- tests/run-macros/quote-match-poly-function/Macro_1.scala | 2 ++ tests/run-macros/quote-match-poly-function/Test_2.scala | 3 ++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala b/compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala index f028e0286a73..2452a361813d 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala @@ -644,8 +644,13 @@ class QuoteMatcher(debug: Boolean) { val meth = newAnonFun(ctx.owner, methTpe) def bodyFn(lambdaArgss: List[List[Tree]]): Tree = { - val typeArgsMap = ptTypeVarSymbols.zip(lambdaArgss.head.map(_.tpe)).toMap - val argsMap = argIds.view.map(_.symbol).zip(lambdaArgss.tail.head).toMap + val (typeParams, params) = if typeArgs.isEmpty then + (List.empty, lambdaArgss.head) + else + (lambdaArgss.head.map(_.tpe), lambdaArgss.tail.head) + + val typeArgsMap = ptTypeVarSymbols.zip(typeParams).toMap + val argsMap = argIds.view.map(_.symbol).zip(params).toMap val body = new TreeTypeMap( typeMap = if typeArgs.isEmpty then IdentityTypeMap diff --git a/tests/run-macros/quote-match-poly-function.check b/tests/run-macros/quote-match-poly-function.check index bd79ed7f06ef..cc03b5474054 100644 --- a/tests/run-macros/quote-match-poly-function.check +++ b/tests/run-macros/quote-match-poly-function.check @@ -1,2 +1,3 @@ -not matched case 2 matched => 5 +case 3 matched => truthy +case 4 matched => truthy diff --git a/tests/run-macros/quote-match-poly-function/Macro_1.scala b/tests/run-macros/quote-match-poly-function/Macro_1.scala index b8d266f419ef..1f3944d23bf2 100644 --- a/tests/run-macros/quote-match-poly-function/Macro_1.scala +++ b/tests/run-macros/quote-match-poly-function/Macro_1.scala @@ -7,4 +7,6 @@ def testExprImpl1(body: Expr[Any])(using Quotes): Expr[String] = '{ "case 2 matched => " + $b(2, 3) } case '{ [A] => (x : A, y : A) => $b[A](x, y) : A } => '{ "case 3 matched => " + $b[String]("truthy", "falsy") } + case '{ [A] => (x : A, y : A) => $b[A](x, y) : (A, A) } => + '{ "case 4 matched => " + $b[String]("truthy", "falsy")._2 } case _ => Expr("not matched") diff --git a/tests/run-macros/quote-match-poly-function/Test_2.scala b/tests/run-macros/quote-match-poly-function/Test_2.scala index c98dc7ff29ef..0b395dee86b7 100644 --- a/tests/run-macros/quote-match-poly-function/Test_2.scala +++ b/tests/run-macros/quote-match-poly-function/Test_2.scala @@ -1,3 +1,4 @@ @main def Test: Unit = - println(testExpr([B] => (x : B, y : B) => x)) // Should match case 3 println(testExpr([B] => (x : Int, y : Int) => x + y)) // Should match case 2 + println(testExpr([B] => (x : B, y : B) => x)) // Should match case 3 + println(testExpr([B] => (x : B, y : B) => (y, x))) // Should match case 4