Skip to content

Nameref (local -n / typeset -n) not implemented #354

@chaliy

Description

@chaliy

Description

Bash namerefs (local -n, typeset -n, declare -n) are not implemented. All 14 nameref tests are skipped.

Scope

  • local -n ref=var - create a nameref local variable
  • typeset -n ref / typeset +n ref - toggle nameref attribute
  • declare -n ref=var - declare nameref
  • Reading through nameref: echo $ref should dereference
  • Writing through nameref: ref=value should modify target
  • ${!ref} with namerefs - inverted behavior (shows target name instead of dereferencing)
  • Nameref chains: ref1 -> ref2 -> var
  • Nameref to array elements: ref='arr[2]'
  • Nameref via dynamic scoping in functions
  • unset ref should unset the target, not the ref

Repro

x=hello
declare -n ref=x
echo $ref
# bashkit outputs: x (wrong, should dereference to: hello)

ref=world
echo $x
# bashkit outputs: hello (wrong, should be: world — mutation through ref)

local -n arr_ref=myarr
myarr=(a b c)
echo ${arr_ref[1]}
# bashkit outputs: (empty) (wrong, should be: b)

Test coverage

14 skipped tests in crates/bashkit/tests/spec_cases/bash/nameref.test.sh (PR #351).

Oils reference: https://github.com/oilshell/oil/blob/master/spec/nameref.test.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions