Repository navigation
Applying a function does not rename the enclosing function's parameters inside a nested block - #656
Closed
enumeratio wants to merge 1 commit into
Closed
enumeratio wants to merge 1 commit into
enumeratio wants to merge 1 commit into
Conversation
…rs inside a nested block
arnog
added a commit
that referenced
this pull request
Nov 22, 2026
…ther argument mentions the same name (#632, #655; PRs #633 and #656 by enumeratio) The scope of a nested Block holds the binding of each enclosing parameter its body reads. parameterSubBinds took that entry for a binder of the Block, so the capture check renamed the parameter there (a_1, acc_1) and nothing substituted the renamed occurrence. An entry that holds the binding of a function-literal parameter is no longer a binder of the Block; the literal binds it at its own Function node. PRs #633 and #656 make the same fix. This lands the source of #633 and the tests of both. Co-authored-by: enumeratio <314378874+enumeratio@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the inner function
v -> bodywas applied to a value that mentions a parameteraccof the enclosing function, the capture check counted theaccentry that a nestedBlockholds (because its body readsacc) as a binder of that block. It renamedacctoacc_1there, and nothing substituted the renamed occurrence, soacc_1(andk_1) leaked into the result: aFoldwhose step applies such a typed let gave[5, At(acc_1, 2), At(acc_1_1, 3)], not[5, 6, 7].parameterSubBindsnow does not count a scope entry that holds the binding of a parameter of an enclosing function literal as a binder. ABlockstill binds its own locals, and a nested literal still binds its own parameters.Kept: renaming of a real binder whose name is free in the value (
y -> (x -> y^x)applied toxstill givesx_1 -> x^x_1), and a user symbol namedacc_1is left alone.Tests:
test/compute-engine/apply-capture-rename.test.tscovers the repro, the bareApplyvariant, aFilterin place of theMap, two levels of nesting, with and withoutTyped, throughevaluate()and.N(), and a declaredacc_1. The existing apply, fold, reduce, substitution and closure tests pass unchanged.Fixes #655