Funny interaction between `set -ql` and `if` #2502

ridiculousfish opened this Issue Oct 23, 2015 · 1 comment


None yet

2 participants

set -l foo bar
if set -ql foo
  echo Found it

This does not echo "Found it" like one might expect. I guess the if statement introduces a new scope which contains the condition, so the local variable is not found. But even so, it really seems like this ought to succeed.

set -ql should probably check up to the function boundary.

@ridiculousfish ridiculousfish modified the milestone: fish-future, next-2.x Oct 23, 2015
@ridiculousfish ridiculousfish added a commit that closed this issue Oct 23, 2015
@ridiculousfish ridiculousfish Make 'set -ql' search up to function scope
Previously 'set -ql' would only look for variables in the
immediate local scope. This was not very useful. It's also
arguably surprising, since a 'set -l' in a function, followed
by a 'set -ql' in a child block, would fail. There was also no
way to check for a function-scoped variable, since omitting the
scope would also pull in global variables.

We could revisit this and introduce an explicit function scope.

Fixes #2502

I want to make set -ql basically mean "check up to function scope" instead of "just check the local scope." I can't think of any reasonable use case for checking just the local scope, since you always know what variables you defined in the local scope. Therefore there's no compatibility risk. This is a little asymmetric but I think it's very natural.

This change needs to be mentioned in the release notes.

@faho faho added the releasenotes label Oct 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment