Repository navigation
Merged
Conversation
…unction (#2326, D161) `names.iter().any(s.contains(it))` was refused: the parser wrapped the closure at the innermost call argument holding `it`, so the program read `any(s.contains(x => x))`. Only `any(n => s.contains(n))` type-checks, and which call owns `it` depends on parameter types, which the parser cannot see (#2660 fixed the half where codegen aborted on it). The fix moves that decision to Sema, the owner of the call's types: - Parser.parse_call records, for each argument that is or holds an `it` closure, its extra slot and the enclosing call argument holding it (AstPool implicit_it_slots / implicit_it_parents; copied by astpool_clone_deep, which every program goes through). - Sema.check_expr_with_expected notes such an argument's demand while it is checked; check_closure, finding an `it` closure with no function demand, walks the parents to the nearest argument demanding a one-parameter function (it_closure_host), records the move and suppresses errors until that argument is done. - An argument holding an `it` closure defers like a closure with an untyped parameter (arg_waits_for_fn_demand, formerly closure_has_untyped_param), so a generic call checks it against the function type its other arguments bind. - D128's body loop applies the moves (apply_it_closure_moves: slots are relinked, no node is created) and checks the body again. The moves are the loop's own: a generic instance checked inside it (std's iter_map, found in lldb applying main's move and rechecking itself) keeps its own list. Past 64 passes it is a loud BUG, never a silent accept. - A move that nests one `it` closure in another is §9.3.1's E0951. Tests: behav_2326_it_belongs_to_nearest_fn_argument (any, all, a filter whose closure already owns another `it`, two value calls in between) and err_2326_moved_it_closure_nests. The 34 fixtures whose code uses `it`, the `it` diagnostic fixtures and parser_unit_test pass on stage1; int-local-rechecks over src/main.w stays 21. Delegated under D98 as D161; §9.3.1 gains the nearest-argument rule.
it closure is the nearest argument that takes a function (#2326, D161)
ehartford
marked this pull request as ready for review
October 26, 2026 08:24
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.
names.iter().any(s.contains(it))was refused: the parser wrapped theclosure at the innermost call argument holding
it, so the program readany(s.contains(x => x)). Onlyany(n => s.contains(n))type-checks, andwhich call owns
itdepends on parameter types, which the parser cannotsee (#2660 fixed the half where codegen aborted on it).
The fix moves that decision to Sema, the owner of the call's types:
itclosure, its extra slot and the enclosing call argument holding it
(AstPool implicit_it_slots / implicit_it_parents; copied by
astpool_clone_deep, which every program goes through).
is checked; check_closure, finding an
itclosure with no functiondemand, walks the parents to the nearest argument demanding a
one-parameter function (it_closure_host), records the move and
suppresses errors until that argument is done.
itclosure defers like a closure with anuntyped parameter (arg_waits_for_fn_demand, formerly
closure_has_untyped_param), so a generic call checks it against the
function type its other arguments bind.
relinked, no node is created) and checks the body again. The moves are
the loop's own: a generic instance checked inside it (std's iter_map,
found in lldb applying main's move and rechecking itself) keeps its
own list. Past 64 passes it is a loud BUG, never a silent accept.
itclosure in another is §9.3.1's E0951.Tests: behav_2326_it_belongs_to_nearest_fn_argument (any, all, a filter
whose closure already owns another
it, two value calls in between) anderr_2326_moved_it_closure_nests. The 34 fixtures whose code uses
it, theitdiagnostic fixtures and parser_unit_test pass on stage1;int-local-rechecks over src/main.w stays 21.
Delegated under D98 as D161; §9.3.1 gains the nearest-argument rule.
Closes #2326