@@ -206,12 +206,31 @@ object QuoteMatcher {
206
206
// Matches an open term and wraps it into a lambda that provides the free variables
207
207
case Apply (TypeApply (Ident (_), List (TypeTree ())), SeqLiteral (args, _) :: Nil )
208
208
if pattern.symbol.eq(defn.QuotedRuntimePatterns_higherOrderHole ) =>
209
+
210
+ /* Some of method symbols in arguments of higher-order term hole are eta-expanded.
211
+ * e.g.
212
+ * g: Int -> Int
213
+ * => {
214
+ * def $anonfun(y: Int): Int = g(y)
215
+ * closure($anonfun)
216
+ * }
217
+ * This function restores the symbol of the original method from
218
+ * the eta-expanded function.
219
+ */
220
+ def getCapturedIdent (arg : Tree )(using Context ): Ident =
221
+ arg match
222
+ case id : Ident => id
223
+ case Block (DefDef (_, _, _, Apply (id : Ident , _)):: _, _) => id
224
+ case Apply (id : Ident , _) => id
225
+ case y => ???
226
+
209
227
val env = summon[Env ]
210
- val capturedArgs = args.map(_.symbol)
211
- val captureEnv = env.filter((k, v) => ! capturedArgs.contains(v))
228
+ val capturedIds = args.map(getCapturedIdent)
229
+ val capturedSymbols = capturedIds.map(_.symbol)
230
+ val captureEnv = env.filter((k, v) => ! capturedSymbols.contains(v))
212
231
withEnv(captureEnv) {
213
232
scrutinee match
214
- case ClosedPatternTerm (scrutinee) => matchedOpen(scrutinee, pattern.tpe, args , env)
233
+ case ClosedPatternTerm (scrutinee) => matchedOpen(scrutinee, pattern.tpe, capturedIds , env)
215
234
case _ => notMatched
216
235
}
217
236
0 commit comments