Skip to content

fix(hy-syntax): guard return, break/continue, and postfix [/{ against cross-newline fusion (fixes #3159) - #4122

Open
phatloi0010 wants to merge 1 commit into
limitlessprojects:mainfrom
phatloi0010:fix/parser-newline-continuations-3159
Open

phatloi0010 wants to merge 1 commit into
limitlessprojects:mainfrom
phatloi0010:fix/parser-newline-continuations-3159

Conversation

@phatloi0010

Copy link
Copy Markdown
Contributor

Fixes #3159

Summary

Enforces newline sensitivity (self.same_line_as_prev()) across the four remaining statement and postfix continuation sites in compiler/crates/hy-syntax/src/parser.rs:

  1. Tok::Kw("return") (Parser::parse_stmt, lines 914–929):
    • Stop parsing return value expressions when !self.same_line_as_prev(), preventing a bare return from consuming the next line's statement or subsequent unbraced match / select arm head (none => return, <-quit:\n return), and preserving values.is_empty() so Checker::process_return (loans.rs:8950) enforces HYB-E3104 on named borrow results.
  2. Tok::Kw("break") and Tok::Kw("continue") (Parser::parse_stmt, lines 997–1030):
    • Require self.same_line_as_prev() && !matches!(self.nth(1), Tok::Punct("{")) before consuming loop as a break loop / continue loop label, preventing a plain break or continue from stealing the loop keyword of a loop { ... } statement on the next line.
  3. Parser::parse_postfix ({ composite literal attachment & [ index/slice/type-arg postfix, lines 2177–2248):
    • Require self.same_line_as_prev() before attaching { as a struct composite literal T{...} or [ as an index/slice/type-argument postfix, preventing y := xs followed by [0] or { ... } on the next line from fusing into y := xs[0] or xs{...}.

Tests

  • compiler/crates/hy-syntax/src/parser.rs:
    • bare_return_does_not_consume_next_line_or_arm_head
    • break_and_continue_do_not_consume_next_line_loop_stmt
    • line_leading_bracket_and_brace_do_not_fold_into_previous_expr
  • compiler/crates/hy-check/src/loans.rs:
    • newline_after_bare_return_and_slice_alias_enforces_tier0_checks (verifies HYB-E3104 on bare return of named pointer borrow before a next-line expression, and HYB-E3006 when mutating a const slice alias y := xs followed by [0] on the next line).

Note: Re-queued from #3160 onto latest main (a1490f03, behind_by: 0) because #3160 fell past the 100-item open PR page cap (#3852+). #3160 is closed in favor of this PR.

@github-actions github-actions Bot added the bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) label Nov 8, 2026
@phatloi0010
phatloi0010 force-pushed the fix/parser-newline-continuations-3159 branch 24 times, most recently from 6cc27bb to 4750e6d Compare November 9, 2026 21:44
@phatloi0010
phatloi0010 force-pushed the fix/parser-newline-continuations-3159 branch from 4750e6d to 0292dd3 Compare November 9, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify())

Projects

None yet

1 participant