@@ -145,18 +145,18 @@ private[quoted] object Matcher {
145
145
matched(scrutinee.seal)
146
146
147
147
// Matches an open term and wraps it into a lambda that provides the free variables
148
- case (scrutinee, pattern @ Apply (Select (TypeApply (Ident (" patternHole" ), List (Inferred ())), " apply" ), IdentArgs (args))) =>
148
+ case (scrutinee, pattern @ Apply (Select (TypeApply (Ident (" patternHole" ), List (Inferred ())), " apply" ), args0 @ IdentArgs (args))) =>
149
149
def bodyFn (lambdaArgs : List [Tree ]): Tree = {
150
150
val argsMap = args.map(_.symbol).zip(lambdaArgs.asInstanceOf [List [Term ]]).toMap
151
151
new TreeMap {
152
152
override def transformTerm (tree : Term )(given ctx : Context ): Term =
153
- super .transformTerm( tree) match
153
+ tree match
154
154
case tree : Ident => summon[Env ].get(tree.symbol).flatMap(argsMap.get).getOrElse(tree)
155
- case tree => tree
155
+ case tree => super .transformTerm( tree)
156
156
}.transformTree(scrutinee)
157
157
}
158
158
val names = args.map(_.name)
159
- val argTypes = args .map(_ .tpe.widenTermRefExpr)
159
+ val argTypes = args0 .map(x => x .tpe.widenTermRefExpr)
160
160
val resType = pattern.tpe
161
161
val res = Lambda (MethodType (names)(_ => argTypes, _ => resType), bodyFn)
162
162
matched(res.seal)
@@ -183,10 +183,10 @@ private[quoted] object Matcher {
183
183
case (_ : Ref , _ : Ref ) if scrutinee.symbol == pattern.symbol =>
184
184
matched
185
185
186
- case (Apply (fn1, args1), Apply (fn2, args2)) if fn1.symbol == fn2.symbol =>
186
+ case (Apply (fn1, args1), Apply (fn2, args2)) if fn1.symbol == fn2.symbol || summon[ Env ].get(fn1.symbol).contains(fn2.symbol) =>
187
187
fn1 =?= fn2 && args1 =?= args2
188
188
189
- case (TypeApply (fn1, args1), TypeApply (fn2, args2)) if fn1.symbol == fn2.symbol =>
189
+ case (TypeApply (fn1, args1), TypeApply (fn2, args2)) if fn1.symbol == fn2.symbol || summon[ Env ].get(fn1.symbol).contains(fn2.symbol) =>
190
190
fn1 =?= fn2 && args1 =?= args2
191
191
192
192
case (Block (stats1, expr1), Block (binding :: stats2, expr2)) if isTypeBinding(binding) =>
@@ -292,7 +292,7 @@ private[quoted] object Matcher {
292
292
|
293
293
| ${pattern.showExtractors}
294
294
|
295
- |
295
+ |with environment: ${summon[ Env ]}
296
296
|
297
297
|
298
298
| """ .stripMargin)
@@ -317,8 +317,11 @@ private[quoted] object Matcher {
317
317
318
318
private object IdentArgs {
319
319
def unapply (args : List [Term ])(given Context ): Option [List [Ident ]] =
320
- args.foldLeft(Option (List .empty[Ident ])) {
321
- case (Some (acc), id : Ident ) => Some (id :: acc)
320
+ args.foldRight(Option (List .empty[Ident ])) {
321
+ case (id : Ident , Some (acc)) => Some (id :: acc)
322
+ case (Block (List (DefDef (" $anonfun" , Nil , List (params), Inferred (), Some (Apply (id : Ident , args)))), Closure (Ident (" $anonfun" ), None )), Some (acc))
323
+ if params.zip(args).forall(_.symbol == _.symbol) =>
324
+ Some (id :: acc)
322
325
case _ => None
323
326
}
324
327
}
@@ -390,7 +393,7 @@ private[quoted] object Matcher {
390
393
|
391
394
| ${pattern.showExtractors}
392
395
|
393
- |
396
+ |with environment: ${summon[ Env ]}
394
397
|
395
398
|
396
399
| """ .stripMargin)
0 commit comments