Skip to content

enhance set with a flag to force updating the enclosing scope (augments function --no-scope-shadowing) #3540

@kbauer

Description

@kbauer

When using the -S parameter for functions to disabled scope-shadowing, naming conflicts can occur. As a more robust alternative, a mechanism like tcl's upvar would be useful, presumably implemented as option to the set builtin.

Reproduction steps

Create the following fish script file:

#!/usr/bin/env fish

function append -S -a var item
    set $var $$var $item
end 

set x xx; append x xy
echo "Expecting x='xx xy', got x='$x'"
set var xx; append var xy 
echo "Expecting var='xx xy', got var='$var'"
set item xx; append item xy
echo "Expecting item='xx xy', got item='$item'"

and run it. The output will be

Expecting x='xx xy', got x='xx xy'
Expecting var='xx xy', got var='xx'
Expecting item='xx xy', got item='xx'

  • Have you checked if problem occurs with fish 2.4.0?
  • Tried fish without third-party customizations (check sh -c 'env HOME=$(mktemp -d) fish')?

fish version installed (fish --version): fish, version 2.4.0-111-g7356987

OS/terminal used: Windows 10, mintty

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions