Skip to content

D58: a bare let-else else ending the line is a parse error with the else: fix-it (§9.7, §29.13, §30.4) - #1571

Merged
ehartford merged 1 commit into
mainfrom
d58-let-else-conformance
Sep 24, 2026
Merged

ehartford merged 1 commit into
mainfrom
d58-let-else-conformance

Conversation

@ehartford

@ehartford ehartford commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

D58 (blessed 2026-09-22): the else of let PATTERN = EXPR else takes a
§29.13 body (else: stmt, else: + indented block, else { ... }) or a
single diverging expression on the same line (else return -1). else +
newline + an indented block with no introducer is a parse error.

The compiler still accepted it: Parser.parse_let_else_body advanced over an
optional : and handed a NEWLINE straight to parse_block_or_expr, which
takes a newline as the indented-block form whether or not a colon opened it
(#1397 pinned the shape in behav_let_else_block_body's bare_indented).

Now a NEWLINE directly after else reports, at the else:

error: expected ':' after 'else': a let-else branch on the next line is a body (§9.7)
= help: write else: to introduce the indented block; only a single
diverging expression may follow a bare else, on the same line

and parses on as if the colon were written, so the indented branch raises
nothing further (one error per site; a dedented next line still adds the
#1382 indented-block error).

Matrix (stage1 before -> after), let/var/unit-variant heads:
else\n ok -> error + help (let, var, let A = s, trailing comment)
else\n indented-block error -> both errors
else return -1 ok -> ok
else: return -1 ok -> ok
else:\n ok -> ok
else { ... } / multi ok -> ok
else print("x") must-diverge error -> unchanged

Tree rewrite: tools/migrate_let_else_colon.w (Lexer-selected: an else
token followed by a newline token whose logical line starts with let/var)
over src lib tools test examples build build.w found one site, the
behav_let_else_block_body cell that pinned the removed form; it now writes
else: (renamed indented_option). No release UAT fixture, example or blog
program used the form. stage1 check src/main.w: ok.

New fixture: test/compile_errors/err_let_else_bare_else_next_line.w.

Stack #1582, layer 1/11. Draft until the batch battery is green (D56).

… `else:` fix-it (§9.7, §29.13, §30.4)

D58 (blessed 2026-09-22): the `else` of `let PATTERN = EXPR else` takes a
§29.13 body (`else: stmt`, `else:` + indented block, `else { ... }`) or a
single diverging expression on the same line (`else return -1`). `else` +
newline + an indented block with no introducer is a parse error.

The compiler still accepted it: Parser.parse_let_else_body advanced over an
optional `:` and handed a NEWLINE straight to parse_block_or_expr, which
takes a newline as the indented-block form whether or not a colon opened it
(#1397 pinned the shape in behav_let_else_block_body's `bare_indented`).

Now a NEWLINE directly after `else` reports, at the `else`:

  error: expected ':' after 'else': a let-else branch on the next line is a body (§9.7)
    = help: write `else:` to introduce the indented block; only a single
      diverging expression may follow a bare `else`, on the same line

and parses on as if the colon were written, so the indented branch raises
nothing further (one error per site; a dedented next line still adds the
#1382 indented-block error).

Matrix (stage1 before -> after), let/var/unit-variant heads:
  else\n<block>            ok -> error + help   (let, var, `let A = s`, trailing comment)
  else\n<dedented>         indented-block error -> both errors
  else return -1           ok -> ok
  else: return -1          ok -> ok
  else:\n<block>           ok -> ok
  else { ... } / multi     ok -> ok
  else print("x")          must-diverge error -> unchanged

Tree rewrite: tools/migrate_let_else_colon.w (Lexer-selected: an `else`
token followed by a newline token whose logical line starts with let/var)
over src lib tools test examples build build.w found one site, the
behav_let_else_block_body cell that pinned the removed form; it now writes
`else:` (renamed indented_option). No release UAT fixture, example or blog
program used the form. `stage1 check src/main.w`: ok.

New fixture: test/compile_errors/err_let_else_bare_else_next_line.w.
@ehartford
ehartford added this pull request to stack #1582 September 23, 2026 21:37
@ehartford ehartford changed the title d58 let else conformance D58: a bare let-else else ending the line is a parse error with the else: fix-it (§9.7, §29.13, §30.4) Sep 23, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Stack #1582 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main 02301f8 + #1571 → … → #1581 (head dca1a8f; every PR head is a tested commit): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Merges cleanly into main. Merge the stack: gh stack merge 1581 --squash.

@ehartford
ehartford marked this pull request as ready for review September 23, 2026 22:04
This was referenced Sep 23, 2026
@ehartford
ehartford merged commit 01c2baa into main Sep 24, 2026
@ehartford
ehartford deleted the d58-let-else-conformance branch September 24, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant