Skip to content

fix: implement var operators, IFS splitting, parser errors, nameref, alias (#352 #354 #355 #358 #360)#389

Merged
chaliy merged 7 commits intomainfrom
claude/process-issues-and-prs-Vvs93
Feb 28, 2026
Merged

fix: implement var operators, IFS splitting, parser errors, nameref, alias (#352 #354 #355 #358 #360)#389
chaliy merged 7 commits intomainfrom
claude/process-issues-and-prs-Vvs93

Conversation

@chaliy
Copy link
Contributor

@chaliy chaliy commented Feb 28, 2026

Summary

This PR bundles five bug-fix issues, resolving 58 previously-skipped spec tests:

#358 - Variable operators on $@ and arrays (14 unskipped)

  • Add colon_variant flag to distinguish :- :+ := :? from - + = ?
  • Add resolve_param_expansion_name() for array subscripts and special params
  • Add expand_operand() for lazy evaluation of operand expressions
  • Rewrite apply_parameter_op() with proper colon/no-colon semantics
  • Fix set -- encoding to preserve empty positional parameters

#352 - IFS-based word splitting (10 unskipped)

  • Apply IFS word splitting to unquoted variable/command/arithmetic expansions
  • Implement POSIX-compliant ifs_split() (whitespace collapse, non-ws delimiters, mixed IFS)
  • Add proper $@/$* field expansion ("$@" preserves params, "$*" joins with IFS)

#360 - Parser syntax error detection (7 unskipped)

  • Add Token::Error variant for lexer error reporting
  • Detect empty bodies in function/while/until/for/select/if constructs
  • Detect unterminated single and double quotes

#354 - Nameref variables (13 unskipped)

  • Implement local -n / declare -n / typeset -n nameref support
  • Nameref resolution for variable read, write, unset, and ${!ref} expansion
  • Array access through namerefs, for loop variable nameref, unset -n

#355 - Alias expansion (14 unskipped)

  • Implement alias and unalias builtins
  • Alias expansion in command execution with recursion guard
  • Trailing-space alias chaining, subshell isolation, shopt expand_aliases

Test plan

  • All bash spec tests pass (58 previously skipped tests now pass)
  • Bash comparison tests pass (100% match with real bash)
  • Clippy clean, cargo fmt clean
  • All lib unit tests pass

Closes #358
Closes #352
Closes #360
Closes #354
Closes #355

- Add colon_variant flag to ParameterExpansion AST to distinguish
  :- from - (unset-or-empty vs unset-only)
- Add resolve_param_expansion_name() for array subscripts and special params
- Add expand_operand() for lazy evaluation of operand expressions
- Rewrite apply_parameter_op() with proper colon/no-colon semantics
- Fix set -- encoding to preserve empty positional parameters
- Remove 14 skip markers from var-op-test.test.sh

Closes #358

https://claude.ai/code/session_01QbjrsMFJbHy5XfHCzA6TjM
- Apply IFS word splitting to unquoted variable/command/arithmetic
  expansions in command arguments and for/select loops
- Implement POSIX-compliant ifs_split() with proper handling of:
  - IFS whitespace chars (collapse, strip leading/trailing)
  - IFS non-whitespace chars (produce empty fields between adjacent)
  - Mixed IFS (<ws><nws><ws> = single delimiter)
  - Empty IFS (no splitting) and unset IFS (default space/tab/newline)
- Add proper $@/$* field expansion in expand_word_to_fields:
  - "$@" preserves individual positional params
  - "$*" joins with first char of IFS
  - Unquoted $@/$* subject to IFS splitting
- Skip IFS splitting for assignment-like words (e.g., result="$1")
- Remove 10 skip markers from word-split.test.sh

Closes #352

https://claude.ai/code/session_01QbjrsMFJbHy5XfHCzA6TjM
…ucts (#360)

- Reject empty bodies in brace groups, while/until/for/select loops, and if/elif/else clauses
- Detect unterminated single and double quoted strings in lexer via Token::Error variant
- Add check_error_token() to parser for propagating lexer errors
- Remove skip markers from 7 spec tests that now pass
- Add 9 unit tests for new error detection

https://claude.ai/code/session_01QbjrsMFJbHy5XfHCzA6TjM
@chaliy chaliy changed the title fix(interpreter): implement variable operators on $@ and arrays fix: implement var operators, IFS word splitting, parser error detection (#352, #358, #360) Feb 28, 2026
#354)

Add support for bash nameref variables via local -n, declare -n, and
typeset -n. Namerefs create aliases that redirect reads/writes to the
target variable.

Changes:
- local handler: parse -n flag, store _NAMEREF_ marker + local scope
- declare/typeset: handle +n to remove nameref, -n without =value uses
  existing variable value as target
- unset: resolve nameref (unset target), -n flag removes nameref itself
- ${!ref}: for namerefs returns target name (bash inversion behavior)
- ArrayAccess: resolve nameref for array names, handle a[N] targets
- Array writes: resolve nameref for assignment target array names
- for loop: use set_variable to respect nameref on loop variable
- expand_variable: handle resolved names containing array index (a[2])

13 of 14 nameref tests now pass. 1 skipped due to pre-existing parser
limitation with local arr=(...) syntax.

https://claude.ai/code/session_01QbjrsMFJbHy5XfHCzA6TjM
Add alias/unalias builtins and alias expansion to the interpreter:

- aliases HashMap on Interpreter for storing alias definitions
- alias builtin: define (alias name=value), list (alias), query (alias name)
- unalias builtin: remove single alias or all (-a)
- Alias expansion in execute_simple_command: when expand_aliases shopt
  is enabled, unquoted literal command names are checked against aliases
  and expanded by re-parsing the substituted command string
- Recursion prevention via expanding_aliases HashSet (handles alias
  echo='echo foo' without infinite loop)
- Trailing space chaining: alias values ending in space trigger alias
  expansion of the next word
- Only plain literal words are alias-expanded (not $var or $(cmd))
- Pipeline stdin forwarded through alias expansion
- Subshell save/restore of aliases

14 of 15 alias spec tests now pass. 1 skipped due to pre-existing
lexer limitation (single-quote context lost in mid-word tokens).

https://claude.ai/code/session_01QbjrsMFJbHy5XfHCzA6TjM
@chaliy chaliy changed the title fix: implement var operators, IFS word splitting, parser error detection (#352, #358, #360) fix: implement var operators, IFS splitting, parser errors, nameref, alias (#352 #354 #355 #358 #360) Feb 28, 2026
@chaliy chaliy merged commit f7327c6 into main Feb 28, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants