Skip to content

For-loops and variable change events #8384

@faho

Description

@faho

While working on reducing the overhead of running for-loops, I stumbled upon one weird fact:

> function foo --on-variable foo; echo $argv $foo; end
> for foo in 1 2 3; end
VARIABLE SET FOO
VARIABLE SET FOO
VARIABLE SET FOO
VARIABLE SET FOO

See how that calls the event handler four times? That's because this called parser::set_var_and_fire to set the variable initially, which pins it to the outer scope.

That's probably useless.

However, I'm not sure the events here have a use in general. The reason is that for sets the variable as a local to the enclosing block, so no variable handler would ever be able to touch it?

Do we want to just remove the superfluous handler or the event firing here in general?

(or do we even want to abolish events for local variables entirely?)

Is there a use here I'm not seeing?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions