Skip to content

conformance: fix bash diagnostic regressions - #777

Merged
ewhauser merged 3 commits into
mainfrom
ewhauser/fix-bash-conformance-batch
Mar 29, 2026
Merged

ewhauser merged 3 commits into
mainfrom
ewhauser/fix-bash-conformance-batch

Conversation

@ewhauser

Copy link
Copy Markdown
Owner

Summary

  • fix bash-style getopts, parser, and arithmetic diagnostics in several conformance cases
  • match bash for readonly temp bindings in simple-command prefix assignments
  • remove the resolved xfails from the bash conformance manifest

Testing

  • make lint
  • go test ./shell/syntax ./shell/expand ./internal/shell/interp
  • GBASH_CONFORMANCE_BASH=$(./scripts/ensure-bash.sh) GBASH_RUN_CONFORMANCE=1 go test ./internal/conformance -run 'TestConformance/bash/oils/builtin-getopts.test.sh$' -count=1
  • GBASH_CONFORMANCE_BASH=$(./scripts/ensure-bash.sh) GBASH_RUN_CONFORMANCE=1 go test ./internal/conformance -run 'TestConformance/bash/oils/toysh-posix.test.sh$|TestConformance/bash/oils/paren-ambiguity.test.sh$' -count=1

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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".

Comment thread internal/shell/interp/runner.go Outdated
Comment on lines +1454 to +1457
if as.Ref.Index != nil {
r.errf("`%s': not a valid identifier\n", printVarRef(as.Ref))
r.exit.code = 1
return restores

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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".

Comment thread shell/syntax/parser.go
"`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]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Comment thread shell/syntax/parser.go
Comment on lines +1775 to +1776
if semi := strings.IndexRune(e.SourceLine, ';'); semi >= 0 {
return bashCompatLeadingToken(e.SourceLine[semi+1:])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 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".

Comment thread shell/expand/arith.go
message := "arithmetic syntax error: invalid arithmetic operator"
if arithRuntimeIsExpressionError(tokenText) {
message = "syntax error in expression"
message = "arithmetic syntax error in expression"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +1099 to +1100
if file := r.currentCallFile(); file != "" && file != "stdin" {
return path.Clean(file) + ": "

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@ewhauser
ewhauser merged commit bfbe071 into main Mar 29, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/fix-bash-conformance-batch branch March 29, 2026 13:37
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