Skip to content

feat(interpreter): implement recursive variable deref and array access in arithmetic#373

Merged
chaliy merged 1 commit intomainfrom
claude/fix-361-arith-dynamic-Vvs93
Feb 27, 2026
Merged

feat(interpreter): implement recursive variable deref and array access in arithmetic#373
chaliy merged 1 commit intomainfrom
claude/fix-361-arith-dynamic-Vvs93

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Feb 27, 2026

Summary

  • Implement recursive variable dereferencing in arithmetic context: bare variable names are recursively resolved until a numeric value is found (e.g. b=a; a=3; $((b+1)) yields 4)
  • Add expression re-evaluation: variable values containing arithmetic expressions are evaluated as sub-expressions with proper grouping (e.g. x='1+2'; $((x*3)) yields 9)
  • Add array element access in arithmetic: arr[expr] evaluates the index expression and looks up the array element
  • Handle double-quoted substitution in arithmetic context by stripping quotes

Closes #361

Test plan

  • Enabled 5 previously-skipped spec tests in arith-dynamic.test.sh
  • All 1015 library unit tests pass
  • All bash spec tests pass (1184 passed, 0 failed)
  • Bash comparison tests pass (vs real bash)
  • cargo fmt --check clean
  • Pre-existing clippy warning unrelated to this change (resolve_redirect_url dead code)

@chaliy chaliy force-pushed the claude/fix-361-arith-dynamic-Vvs93 branch from 22994ea to 2267da8 Compare February 27, 2026 23:14
…s in arithmetic

Closes #361

- Recursive variable dereferencing: bare names in $((...)) are
  recursively resolved (b=a; a=3; $((b+1)) -> 4)
- Expression re-evaluation: variable values containing expressions
  are evaluated as arithmetic sub-expressions (x='1+2'; $((x*3)) -> 9)
- Array element access: arr[expr] in arithmetic evaluates the index
  expression and looks up the array element
- Quoted substitution: "$x" in arithmetic strips quotes, behaves as $x
- THREAT[TM-DOS-026]: depth limit prevents infinite recursion
@chaliy chaliy force-pushed the claude/fix-361-arith-dynamic-Vvs93 branch from 2267da8 to ede6774 Compare February 27, 2026 23:25
@chaliy chaliy merged commit 76be440 into main Feb 27, 2026
16 checks passed
@chaliy chaliy deleted the claude/fix-361-arith-dynamic-Vvs93 branch March 12, 2026 03:43
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.

Arithmetic: recursive variable deref, array access, quoted substitution not implemented

2 participants