Skip to content

fix(interpreter): respect parentheses in conditional precedence - #1952

Merged
chaliy merged 1 commit into
mainfrom
2026-06-05-propose-fix-for-parenthesized-conditional-bug
Jun 5, 2026
Merged

chaliy merged 1 commit into
mainfrom
2026-06-05-propose-fix-for-parenthesized-conditional-bug

Conversation

@chaliy

@chaliy chaliy commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • A recent change split [[ ]] conditionals on || before && but did not track parenthesis depth, allowing inner || inside parentheses to be treated as a top-level operator and producing incorrect evaluations.

Description

  • Add depth-aware helpers and only split on ||/&& when the operator is at the current parenthesis depth, implemented as find_top_level_conditional_*_operator for both raw Word and expanded-String paths in crates/bashkit/src/interpreter/mod.rs.
  • Tighten parenthesis stripping so outer parentheses are removed only when they wrap the entire expression, via conditional_words_wrapped and conditional_args_wrapped for Word and String code paths respectively.
  • Preserve lazy short-circuit evaluation behavior while using the depth-aware operator lookup so semantics and short-circuiting remain unchanged.
  • Add two bash spec tests covering ( "$a" || "$b" ) && "$c" for both false and true scenarios in crates/bashkit/tests/spec_cases/bash/conditional.test.sh.

Testing

  • Ran the bash spec suite subset: cargo test -p bashkit --test integration bash_spec_tests -- --nocapture, which passed (spec harness reported all bash spec tests passed).
  • Ran formatting and lint checks: cargo fmt --check and cargo clippy -p bashkit --test integration -- -D warnings, both succeeded.

Codex Task

Copilot AI review requested due to automatic review settings June 5, 2026 19:49

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.

Pull request overview

This PR fixes [[ ... ]] conditional parsing/evaluation in bashkit so &&/|| splitting respects parentheses depth, preventing inner operators inside (...) from being treated as top-level and preserving correct precedence and short-circuit behavior.

Changes:

  • Add depth-aware helpers to find top-level || / && operators for both raw-Word and expanded-String evaluation paths.
  • Tighten outer-parentheses stripping so parentheses are removed only when they wrap the entire conditional expression.
  • Add bash spec tests covering ( "$a" || "$b" ) && "$c" for true/false scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/bashkit/src/interpreter/mod.rs Makes conditional operator splitting and parentheses stripping depth-aware to preserve correct precedence/short-circuiting.
crates/bashkit/tests/spec_cases/bash/conditional.test.sh Adds regression tests ensuring parenthesized `

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2997 to +3001
match Self::conditional_word_literal(&words[i]) {
Some(")") => depth += 1,
Some("(") => depth = depth.saturating_sub(1),
Some(found) if found == op && depth == 0 && i > 0 => return Some(i),
_ => {}
Comment on lines +3010 to +3014
match args[i].as_str() {
")" => depth += 1,
"(" => depth = depth.saturating_sub(1),
found if found == op && depth == 0 && i > 0 => return Some(i),
_ => {}
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 3aebade Commit Preview URL Jun 05 2026, 08:17 PM

@chaliy
chaliy merged commit d2d0d7f into main Jun 5, 2026
36 checks passed
@chaliy
chaliy deleted the 2026-06-05-propose-fix-for-parenthesized-conditional-bug branch June 5, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants