Skip to content

interpreter: keep the earlier exit status on a bare exit in END - #190

Merged
Alonely0 merged 2 commits into
uutils:mainfrom
emreocell:fix-bare-exit-end
Nov 20, 2026
Merged

Alonely0 merged 2 commits into
uutils:mainfrom
emreocell:fix-bare-exit-end

Conversation

@emreocell

Copy link
Copy Markdown
Contributor

Fixes #182

BEGIN { exit 3 } END { exit } exited with 0 because a bare exit was lowered to exit 0. POSIX says that in END it keeps the status of an earlier exit.

How

A bare exit is now its own instruction (ExitKeep) and CtrlSig::Exit carries an Option<i32>. end_event_loop uses the status it was called with when END ends with a bare exit; everywhere else a bare exit still means status 0 as before.

Tests

  • Added bare_exit_in_end_keeps_status: the case from the issue plus BEGIN { exit 3 } END { exit }, BEGIN { exit 3 } END { exit 4 } (explicit status still wins) and a bare exit in both (0).
  • cargo test --workspace passes, cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --all --check are clean.
  • I could not compare against gawk (not installed here); the expected output is the one quoted in the issue.

Copilot AI balanced review requested due to automatic review settings November 19, 2026 03:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

GNU awk testsuite comparison:

Test results comparison:
  Current:   TOTAL: 666 / PASSED: 105 / FAILED: 463 / SKIPPED: 98
  Reference: TOTAL: 666 / PASSED: 104 / FAILED: 464 / SKIPPED: 98

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + exitval3

Comment thread src/event.rs Outdated
CtrlSig::NextFile => break, // clean-up & read next file
CtrlSig::Exit(code) => return self.end_event_loop(code).map(|_| ()),
CtrlSig::Exit(code) => {
return self.end_event_loop(code.unwrap_or(0)).map(|_| ());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwrap_or(0) is now repeated 4 times. Could end_event_loop take the Option<i32> and do end_code.or(code).unwrap_or(0) itself?

Copilot AI balanced review requested due to automatic review settings November 19, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@emreocell

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Done in e9bf24d: end_event_loop now takes the earlier status as an Option<i32> and does end_code.or(code).unwrap_or(0) itself, so the four callers just pass the code on. main_event_loop passes None and the fatal-diagnostics path passes Some(AWK_FATAL_CODE), so behavior is unchanged.

One note: I do not have a Rust toolchain on this machine, so I have not compiled or run this follow-up locally. I checked the types and the other call sites by reading the code, so I am relying on CI here. If it fails I will fix it right away.

@github-actions

Copy link
Copy Markdown

GNU awk testsuite comparison:

Test results comparison:
  Current:   TOTAL: 666 / PASSED: 105 / FAILED: 463 / SKIPPED: 98
  Reference: TOTAL: 666 / PASSED: 104 / FAILED: 464 / SKIPPED: 98

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + exitval3

Comment thread src/event.rs Resolved
A bare `exit` always exited with 0. Lower it to its own instruction and
signal so that, in END, the status of an earlier exit is kept as POSIX
requires.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:13
@emreocell

Copy link
Copy Markdown
Contributor Author

Done, thanks: it is back to one line and I rebased onto main (the old conflict was in main_event_loop).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions

Copy link
Copy Markdown

GNU awk testsuite comparison:

Test results comparison:
  Current:   TOTAL: 666 / PASSED: 105 / FAILED: 463 / SKIPPED: 98
  Reference: TOTAL: 666 / PASSED: 104 / FAILED: 464 / SKIPPED: 98

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + exitval3

@Alonely0 Alonely0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, so inheritance just for exit codes? That was not in my AWK dark corner bingo card. anyway, thank you very much for the fix!! merging this now :)

@Alonely0
Alonely0 merged commit 5290840 into uutils:main Nov 20, 2026
16 of 18 checks passed
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.

awk: exit without a status in END discards the earlier exit status

4 participants