Repository navigation
Sema: destructuring let/for/with check their subject as a value (#1349) - #1355
Merged
Merged
Conversation
ehartford
force-pushed
the
fix-stage-debug-info
branch
from
September 22, 2026 23:26
01a3cad to
2d3daf5
Compare
…value — `let (a, b) = if c: f() else: (1, 0)` binds (#1349) `let (x, y) = if b > 0: lc(b) else: (1, 0)` was rejected with "tuple pattern requires tuple subject" in any body where the `let` sat in statement position (every void function, and any statement with stmt_pos_depth > 0). §9.7: all pattern forms are available in let/var; an if-expression is an ordinary expression. Exact line (stage2 of fix-stage-debug-info, lldb file:line breakpoints on c04.w `let (x, y) = if b > 0: (7, 8) else: (1, 0)` in `fn main`): Sema.check_let_else at SemaCheck.w:15258 `self.check_expr(value)` entered Sema.check_if_expr, which stopped at 9791 (`self.check_expr(then_body)`, the statement arm) instead of 9787 (value arm); the join at 9825 and the typed_expr_types insert at 9864 never ran, result_type stayed ty_void, and check_pattern reported at 14334. check_if_expr's classification (9749-9756) saw current_value_expr_root == 0 and current_return_type == ty_void / stmt_pos_depth > 0: the subject inherited the enclosing statement's context. A plain `let x = if ...` goes through check_let_binding:9603, which checks its value with check_expr_value_context; the pattern path did not. Fix: every binding construct's subject is a value — check_let_else, check_tuple_destructure, check_for's iterable, check_with_expr's, check_with_tuple's and check_with_implicit's source all use check_expr_value_context. The same statement-context typing made `with if c: t else: u as x:` and `with t(if ...):` fail in MIR lowering ("AST codegen was removed"), `with if ... as (a, b):` report "requires a tuple expression", and `for (x, y) in if c: v else: w` report the tuple pattern error. Matrix (seed / fixed stage2): let (x, y) = if: call | literal error / 4 5 let (x, y) = if: literal | call error / 4 5 let (x, y) = if: call | call error / 4 5 let (x, y) = if: literal | literal error / 7 8 multi-line if, else-if chain, `_` error / ok nested ((p, q), r) = if ... error / 3 4 5 (p, q) = if: nest(b).0 | literal error / 3 4 in a non-void fn error / ok let .Some(v) = if ... else: return error / ok let (x, y) = match / block tail / call ok / ok let t = if ...; let (x, y) = t ok / ok for (x, y) in Vec of tuples ok / ok for (x, y) in if c: v else: w error / ok with if ... as (x, y): error / ok with if ... as t: / with t(if ...): MIR-lowering error / ok var (x, y) = if ...; x = ... error / "cannot assign to immutable" (#1354, separate) let (x, y): (i32, i32) = if ... parse error both (spec shows no annotated pattern let) Check comparison of the baseline stage2 against the fixed stage2 over all 1130 test/behavior and 850 test/compile_errors fixtures: the only difference is the new fixture (plus a c_import temp-path in one message). analyze audit:all and --validate-all ok on the fixture; --debug-alloc leak count 0. The Codegen.debug_push_lexical_block workaround from fix-stage-debug-info stays: stage1 is built by the pinned seed, which has this bug, so the natural spelling fails the :dev build ("tuple pattern requires tuple subject" at Codegen.w). A comment records the spelling to restore once seed.lock names a release with this fix; the fixed stage2 checks src/main.w with the natural spelling ok. Fixture: test/behavior/behav_destructure_value_subject.w. (cherry picked from commit 7e2fff1) (cherry picked from commit de529dc0fa040df0ea9f4357d218ef39689c1854)
ehartford
force-pushed
the
fix-1349-tuple-pattern-if-subject
branch
from
September 23, 2026 01:03
7e2fff1 to
3786a9c
Compare
Contributor
Author
|
Batch battery (seed-driven) on main dd786a4 + #1355 → #1357 → #1370 → #1371 as one linear chain (head 45f8aa4): build ok, :fixpoint ok, :test ok (no reds), :test-green ok, :last-green ok. The four PRs are now stacked exactly as tested (each branch = its commit on top of the previous PR); merge in order #1355, #1357, #1370, #1371, retargeting each to main as its parent merges. |
ehartford
marked this pull request as ready for review
September 23, 2026 01:03
This was referenced Sep 23, 2026
Merged
ehartford
added a commit
that referenced
this pull request
Oct 2, 2026
…ical_block (#1356) (#1961) The #1351 workaround for #1349 (`let (a, b) = if c: f() else: (1, 0)` rejected by the then-pinned seed) is retired: seed.lock has been bumped past 1f4636d (#1355), and the pinned seed builds stage1 with the natural spelling (`src/main build :dev` rc=0). Co-authored-by: Eric Hartford <[email protected]>
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.
Fixes #1349. Stacked on #1351 (
fix-stage-debug-info).Root cause.
Sema.check_let_else(SemaCheck.w:15258) checked the subject withcheck_expr, so it inherited the enclosing statement's context. lldb on a stage2 built from #1351 confirmed it:check_if_exprtook its statement arm (line 9791) instead of the value arm (9787), skipped the join, and returnedty_void.check_patternthen reported the error at 14334. A plainlet(check_let_binding:9603) already usedcheck_expr_value_context. Every binding construct's subject now does: let-pattern, the deadcheck_tuple_destructure, theforiterable, and the source of all threewithforms.Matrix, seed vs. fixed stage2:
let (x, y) = ifcall / literal, literal / call, call / call, literal / literalif,else ifchain,(x, _), nested((p, q), r),nest(b).0armlet .Some(v) = if ... else: returnmatch/ block tail / call /let t = if; let (x, y) = tfor (x, y) inVec of tuplesfor (x, y) in if c: v else: wwith if ... as (x, y):with if ... as t:/with t(if ...):var (x, y) = ...; x = ...let (x, y): (i32, i32) = ...Evidence. Fixture
test/behavior/behav_destructure_value_subject.w(23 cases, expected stdout). I checked all 1130test/behaviorand 850test/compile_errorsfixtures with the baseline stage2 and with the fixed stage2. Only the new fixture changed; one c_import message differs only in its temp path. On the fixture,analyze audit:alland--validate-allpass, and--debug-allocreports a leak count of 0.Codegen workaround stays (seed-gated). The pinned seed builds stage1, and the seed still has this bug, so restoring
let (line, col) = if ...inCodegen.debug_push_lexical_blockfails:dev. The fixed stage2 checkssrc/main.wfine with the natural spelling. A comment marks the spelling to restore onceseed.lockpoints at a release that contains this fix.Iterate tier only:
:devand:stage2. The battery has not run yet.