Skip to content

Commit

Permalink
Add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zeptometer committed Aug 7, 2023
1 parent 3cb8b72 commit f180e03
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions compiler/src/scala/quoted/runtime/impl/QuoteMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/run-macros/quote-match-poly-function.check
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
not matched
case 2 matched => 5
case 3 matched => truthy
case 4 matched => truthy
2 changes: 2 additions & 0 deletions tests/run-macros/quote-match-poly-function/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
3 changes: 2 additions & 1 deletion tests/run-macros/quote-match-poly-function/Test_2.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f180e03

Please sign in to comment.