Skip to content

Restore SingleLine group state after early exits - #23

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/singleline-group-cleanup
Open

Restore SingleLine group state after early exits#23
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/singleline-group-cleanup

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Restore SingleLine's group/first-item stack when a group exits through an exception, throw, return or break, including an exception raised by the output sink. Normal output and the existing boolean return value remain unchanged.

Reproduction

q = PrettyPrint::SingleLine.new([])
q.first? # consume the parent first-item flag
begin
  q.group { raise "example" }
rescue RuntimeError
end
q.first? # currently true from the leaked child; should remain false

Verification

  • rbenv Ruby 4.0.6: existing rake test, 35 tests / 54 assertions, passes before/after.
  • External corpus: 40 checks, 28 failures on main before this patch, zero after; covers both parent/child flag states, four early-exit mechanisms, output failures, and normal return values.
  • 2,000 generated single-/multi-line outputs remain byte-identical.
  • No repository tests added or changed under the contributor's task constraint. Verification scripts are external. Other Ruby engines/versions were not executed locally.

Breaking-change notes

No API removal or normal-output change. A printer reused after an interrupted group now sees the restored parent state. Already-emitted output is not rolled back, and a closing delimiter is not synthesized after failure.

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