From 41516e5164a2bc48094d6104e92f53326f0955ca Mon Sep 17 00:00:00 2001 From: anderium <33520919+anderium@users.noreply.github.com> Date: Fri, 12 Jul 2024 20:21:33 +0200 Subject: [PATCH] Exclude the nameToReplace from valid capture avoidance Probably fixes #125 and #126 --- src/lib/lambda/operations.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/lambda/operations.ts b/src/lib/lambda/operations.ts index f4d4259..1b55a1d 100644 --- a/src/lib/lambda/operations.ts +++ b/src/lib/lambda/operations.ts @@ -113,12 +113,13 @@ function replace(nameToReplace: Name, replacer: Expr, expression: Expr): Expr { // 1: isn't free in the replacer // 2: isn't free in the expression body // 3: isn't captured by an intermediate function in the expression body + // 4: isn't the argument name that is being replaced. const freeInExpressionBody = getFreeVars(expression.body).map( (node) => node.name ); const argNames = getAllArgumentNames(expression.body); let newName = generateNewName( - freeInReplacer.concat(freeInExpressionBody, argNames) + freeInReplacer.concat(freeInExpressionBody, argNames, [nameToReplace]) ); // And make that the new function arg name