Skip to content

fix(interpreter): support recursive function calls inside $() command substitution#1043

Merged
chaliy merged 3 commits intomainfrom
fix/issue-962-recursive-cmdsub
Apr 4, 2026
Merged

fix(interpreter): support recursive function calls inside $() command substitution#1043
chaliy merged 3 commits intomainfrom
fix/issue-962-recursive-cmdsub

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 3, 2026

Summary

  • Fix recursive function calls inside $() command substitution that were silently failing
  • Root cause: expand_command_subs_in_arithmetic executed $() without saving/restoring interpreter state, causing variable mutations to leak from subshell scope
  • Added save/restore of all mutable interpreter state matching the existing CommandSubstitution handler pattern

Test plan

  • recursive_function_command_subst — factorial(5) = 120
  • recursive_depth_3 — nested string building via recursion
  • recursive_cmdsub_var_isolation — variable mutations inside $() in arithmetic don't leak
  • All 1928 existing bash spec tests pass

Closes #962

chaliy added 3 commits April 3, 2026 22:58
… substitution

The expand_command_subs_in_arithmetic helper executed $() command
substitutions without saving/restoring interpreter state (variables,
arrays, functions, traps, etc.), unlike the regular CommandSubstitution
handler. This caused variable mutations inside $() within $(()) to
leak into the parent scope, breaking recursive function calls and
violating subshell isolation semantics.

Add save/restore of all mutable interpreter state around command
substitution execution in expand_command_subs_in_arithmetic, matching
the existing pattern in the WordPart::CommandSubstitution handler.

Closes #962
@chaliy chaliy merged commit abff610 into main Apr 4, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-962-recursive-cmdsub branch April 4, 2026 01:15
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.

Recursive function calls inside $() command substitution silently fail

1 participant