Repository navigation
fix(interpreter): respect parentheses in conditional precedence - #1952
Merged
chaliy merged 1 commit intoJun 5, 2026
Merged
Conversation
There was a problem hiding this comment.
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-Wordand expanded-Stringevaluation 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), | ||
| _ => {} |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | 3aebade | Commit Preview URL | Jun 05 2026, 08:17 PM |
chaliy
deleted the
2026-06-05-propose-fix-for-parenthesized-conditional-bug
branch
June 5, 2026 20:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
[[ ]]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
||/&&when the operator is at the current parenthesis depth, implemented asfind_top_level_conditional_*_operatorfor both rawWordand expanded-Stringpaths incrates/bashkit/src/interpreter/mod.rs.conditional_words_wrappedandconditional_args_wrappedforWordandStringcode paths respectively.( "$a" || "$b" ) && "$c"for both false and true scenarios incrates/bashkit/tests/spec_cases/bash/conditional.test.sh.Testing
cargo test -p bashkit --test integration bash_spec_tests -- --nocapture, which passed (spec harness reported all bash spec tests passed).cargo fmt --checkandcargo clippy -p bashkit --test integration -- -D warnings, both succeeded.Codex Task