Skip to content

interp: fix reverse-loop helper lookup in hook scripts - #786

Merged
ewhauser merged 1 commit into
mainfrom
ewhauser/runtime-hook-cmdsub-fix
Mar 29, 2026
Merged

ewhauser merged 1 commit into
mainfrom
ewhauser/runtime-hook-cmdsub-fix

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • preserve the current loop body exit status across C-style for ((...)) condition and post arithmetic
  • add an interp regression for a reverse loop whose body has an && list that is false before a later hit
  • add a CLI/runtime regression covering standalone helper lookup plus command substitution around an external pipeline

Root Cause

The C-style loop runner was reusing the previous body command status while evaluating the next iteration's arithmetic condition and post expressions. In a reverse lookup helper, an earlier miss such as [[ -x "$candidate" ]] returning false left the loop in status 1, so gbash exited the loop before reaching a later executable hit. That then made provider_bin="$(_find_bin ... )" fail under set -e, even though simpler pieces worked in isolation.

Impact

This fixes a runtime bug where realistic hook-style shell scripts could exit early before using an external command result, despite the helper function and external pipeline both being valid.

Validation

  • make lint
  • go test ./internal/shell/interp
  • go test ./cmd/gbash -run 'TestRunCLISupportsScriptFileArgs|TestRunCLISupportsDashOPipefail|TestRunCLIReverseLoopHelperLookupFeedsExternalPipeline'
  • rebuilt cmd/gbash and reran a standalone shell repro matching the helper lookup plus external pipeline pattern

@ewhauser
ewhauser marked this pull request as ready for review March 29, 2026 19:48
@ewhauser ewhauser changed the title [codex] interp: fix reverse-loop helper lookup in hook scripts interp: fix reverse-loop helper lookup in hook scripts Mar 29, 2026
@ewhauser
ewhauser merged commit 7823e3c into main Mar 29, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/runtime-hook-cmdsub-fix branch March 29, 2026 20:26
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