Also set the read-only flag for non-electric vars

For some reason, we have two places where a variable can be read-only:

- By key in env.cpp:is_read_only(), which is checked via set*

- By flag on the actual env_var_t, which is checked e.g. in
  parse_execution

The latter didn't happen for non-electric variables like hostname,
because they used the default constructor, because they were
constructed via operator[] (or some such C++-iness).

This caused for-loops to crash on an assert if they used a
non-electric read-only var like $hostname or $SHLVL.

Instead, we explicitly set the flag.

We might want to remove one of the two read-only checks, or something?

Fixes #5548.
This commit is contained in:
Fabian Homborg
2019-01-18 19:24:49 +01:00
parent 1398ee9bbb
commit 3847d2e9d1
5 changed files with 23 additions and 0 deletions

View File

@@ -38,6 +38,12 @@ fish: You cannot use read-only variable 'status' in a for loop
for status in a b c
^
####################
# That goes for non-electric ones as well (#5548)
fish: You cannot use read-only variable 'hostname' in a for loop
for hostname in a b c
^
####################
# For loop control vars available outside the for block