Skip to content

fix(interpreter): handle ++/-- in complex arithmetic expressions#916

Merged
chaliy merged 1 commit intomainfrom
fix/issue-903-arith-loop-break
Mar 31, 2026
Merged

fix(interpreter): handle ++/-- in complex arithmetic expressions#916
chaliy merged 1 commit intomainfrom
fix/issue-903-arith-loop-break

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Mar 31, 2026

Summary

  • Fix (( ++i > N )) && break exiting while loops on the first iteration
  • execute_arithmetic_with_side_effects now extracts the variable name from ++var/--var, performs the side effect, and evaluates the remaining expression with the new value substituted
  • Added spec tests for both pre-increment and pre-decrement in loop break patterns

Test plan

  • cargo test --test spec_tests -- bash_spec_tests passes (1829 specs, 0 failures)
  • New tests arith_preincrement_and_break and arith_predecrement_and_break verify correct loop iteration count
  • cargo clippy -- -D warnings clean
  • cargo fmt --check clean

Closes #903

Pre-increment/decrement operators like `++i` in complex expressions
(e.g., `(( ++i > 3 )) && break`) were incorrectly treated as standalone
operations. The variable name extraction now properly identifies the
variable and evaluates the remaining expression with the incremented value.

Closes #903
@chaliy chaliy merged commit 865ee37 into main Mar 31, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-903-arith-loop-break branch March 31, 2026 10:11
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.

bug(interpreter): (( ++i > N )) && break exits while loop on first iteration

1 participant