Skip to content

fix(trap): break/continue in RETURN trap must not leak to caller loop - #1441

Merged
arookieofc merged 1 commit into
masterfrom
fix-1406-break-in-return-trap
Oct 23, 2026
Merged

arookieofc merged 1 commit into
masterfrom
fix-1406-break-in-return-trap

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Summary

break/continue in a function's RETURN trap no longer leaks into the caller's loop. GNU errors with 'only meaningful in a loop' and continues the loop.

Changes

  • src/executor/trap_exec.rs: run_return_trap clears loop_depth/inherited_loop_depth around the trap action, so break/continue see no loop context.

Issues

Fixes #1406

Testing

  • New regression test: tests/issue1406_break_in_return_trap.rs (1 test, passes)
  • Verified: all 3 loop iterations run, break errors on stderr, loop continues

GNU errors 'break: only meaningful in a loop' when break is used in a
function's RETURN trap; the trap runs in the function's return context
which has no loop. Rubash leaked the Break into the caller's loop.

Fixes #1406
@arookieofc
arookieofc merged commit 937d0fd into master Oct 23, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix-1406-break-in-return-trap branch October 30, 2026 01:41
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.

[bug] break/continue in function's RETURN trap leaks into the caller's loop (GNU errors)

1 participant