Commit 76be440
feat(interpreter): implement recursive variable deref and array access in arithmetic (#373)
## 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
- [x] Enabled 5 previously-skipped spec tests in `arith-dynamic.test.sh`
- [x] All 1015 library unit tests pass
- [x] All bash spec tests pass (1184 passed, 0 failed)
- [x] Bash comparison tests pass (vs real bash)
- [x] `cargo fmt --check` clean
- [x] Pre-existing clippy warning unrelated to this change
(`resolve_redirect_url` dead code)
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3cca974 commit 76be440
File tree
2 files changed
+82
-10
lines changed- crates/bashkit
- src/interpreter
- tests/spec_cases/bash
2 files changed
+82
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5774 | 5774 | | |
5775 | 5775 | | |
5776 | 5776 | | |
| 5777 | + | |
| 5778 | + | |
| 5779 | + | |
| 5780 | + | |
| 5781 | + | |
| 5782 | + | |
| 5783 | + | |
| 5784 | + | |
| 5785 | + | |
| 5786 | + | |
| 5787 | + | |
| 5788 | + | |
| 5789 | + | |
| 5790 | + | |
| 5791 | + | |
| 5792 | + | |
| 5793 | + | |
| 5794 | + | |
| 5795 | + | |
| 5796 | + | |
| 5797 | + | |
| 5798 | + | |
| 5799 | + | |
| 5800 | + | |
| 5801 | + | |
| 5802 | + | |
| 5803 | + | |
| 5804 | + | |
5777 | 5805 | | |
5778 | 5806 | | |
| 5807 | + | |
| 5808 | + | |
| 5809 | + | |
| 5810 | + | |
| 5811 | + | |
| 5812 | + | |
| 5813 | + | |
| 5814 | + | |
| 5815 | + | |
| 5816 | + | |
| 5817 | + | |
| 5818 | + | |
| 5819 | + | |
5779 | 5820 | | |
5780 | 5821 | | |
5781 | 5822 | | |
| |||
5794 | 5835 | | |
5795 | 5836 | | |
5796 | 5837 | | |
| 5838 | + | |
| 5839 | + | |
5797 | 5840 | | |
5798 | 5841 | | |
5799 | 5842 | | |
| |||
5833 | 5876 | | |
5834 | 5877 | | |
5835 | 5878 | | |
5836 | | - | |
5837 | | - | |
5838 | | - | |
5839 | | - | |
| 5879 | + | |
| 5880 | + | |
| 5881 | + | |
| 5882 | + | |
| 5883 | + | |
| 5884 | + | |
| 5885 | + | |
| 5886 | + | |
| 5887 | + | |
| 5888 | + | |
| 5889 | + | |
| 5890 | + | |
| 5891 | + | |
| 5892 | + | |
| 5893 | + | |
| 5894 | + | |
| 5895 | + | |
| 5896 | + | |
| 5897 | + | |
| 5898 | + | |
| 5899 | + | |
| 5900 | + | |
| 5901 | + | |
| 5902 | + | |
| 5903 | + | |
| 5904 | + | |
| 5905 | + | |
| 5906 | + | |
| 5907 | + | |
| 5908 | + | |
| 5909 | + | |
| 5910 | + | |
| 5911 | + | |
| 5912 | + | |
| 5913 | + | |
| 5914 | + | |
5840 | 5915 | | |
5841 | | - | |
| 5916 | + | |
| 5917 | + | |
| 5918 | + | |
5842 | 5919 | | |
5843 | 5920 | | |
5844 | 5921 | | |
| |||
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | | - | |
33 | 31 | | |
34 | 32 | | |
35 | 33 | | |
| |||
38 | 36 | | |
39 | 37 | | |
40 | 38 | | |
41 | | - | |
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
| |||
48 | 45 | | |
49 | 46 | | |
50 | 47 | | |
51 | | - | |
52 | 48 | | |
53 | 49 | | |
54 | 50 | | |
| |||
58 | 54 | | |
59 | 55 | | |
60 | 56 | | |
61 | | - | |
62 | 57 | | |
63 | 58 | | |
64 | 59 | | |
| |||
0 commit comments