Repository navigation
conformance: fix bash diagnostic regressions - #777
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d6ce4a13c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if as.Ref.Index != nil { | ||
| r.errf("`%s': not a valid identifier\n", printVarRef(as.Ref)) | ||
| r.exit.code = 1 | ||
| return restores |
There was a problem hiding this comment.
Keep running command after invalid indexed temp assignment
runTempCallAssigns now sets r.exit.code = 1 and returns immediately when a prefix assignment uses an index (as.Ref.Index != nil). In Bash, x[1]=2 echo hi emits a diagnostic but still executes echo and returns the command status, so this change skips command execution for a previously supported flow. Because cmdCall bails out when r.exit is non-OK, any command with an indexed temp binding now fails early instead of matching shell behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 575c647262
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "`select foo` must be followed by `in`, `do`, `;`, or a newline": | ||
| fields := strings.Fields(e.SourceLine) | ||
| if len(fields) >= 2 { | ||
| return bashCompatLeadingToken(strings.TrimPrefix(e.SourceLine, fields[0]+" "+fields[1])) |
There was a problem hiding this comment.
Handle indented/tabbed
for headers when extracting token
The for foo/select foo compatibility path assumes the first two fields are separated by exactly one plain space (fields[0]+" "+fields[1]). When the source line is indented or uses tabs/multiple spaces (for example, for\ti; in ... or for i; in ...), TrimPrefix does not match, so the full line is re-tokenized and the diagnostic reports for as the unexpected token instead of in. This breaks the Bash-compatible error text for common whitespace layouts.
Useful? React with 👍 / 👎.
| if semi := strings.IndexRune(e.SourceLine, ';'); semi >= 0 { | ||
| return bashCompatLeadingToken(e.SourceLine[semi+1:]) |
There was a problem hiding this comment.
Avoid splitting
for ... in errors on quoted semicolons
For `for foo [in words]` must be followed by `do` errors, the new logic finds the token after the first ; in the raw line. This treats semicolons inside quoted words as statement separators, so inputs like for i in "a;b" (missing do) can report an unexpected token from inside the quoted string instead of the real parse context. Because this path is meant to mimic Bash diagnostics, using a raw first-semicolon split produces incorrect messages for valid word lists containing ;.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32b8c7d06a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| message := "arithmetic syntax error: invalid arithmetic operator" | ||
| if arithRuntimeIsExpressionError(tokenText) { | ||
| message = "syntax error in expression" | ||
| message = "arithmetic syntax error in expression" |
There was a problem hiding this comment.
Preserve Darwin arithmetic expression diagnostic format
Changing the diagnostic text to "arithmetic syntax error in expression" makes the Darwin compatibility guard in internal/shell/interp/runner.go ineffective, because that guard only skips the "((: " prefix when diagErr.Message == "syntax error in expression". As a result, macOS now emits a different stderr shape for arithmetic parse failures (for example ((echo hello))) than the behavior this code previously handled explicitly, which can break Bash-parity conformance on Darwin.
Useful? React with 👍 / 👎.
| if file := r.currentCallFile(); file != "" && file != "stdin" { | ||
| return path.Clean(file) + ": " |
There was a problem hiding this comment.
Use shell invocation name for getopts diagnostics
getoptsDiagPrefix() now uses currentCallFile(), which tracks the currently executing frame, so diagnostics emitted inside sourced files/functions are attributed to that file rather than the shell's invocation name ($0). In Bash, getopts errors are prefixed by the main script/shell name, so this change can misreport the source in nested execution contexts (e.g., main.sh sourcing lib.sh where lib.sh runs getopts).
Useful? React with 👍 / 👎.
Summary
Testing