Fix crash if $PWD is used as for-loop variable

for PWD in foo; true; end

prints:

>..src/parse_execution.cpp:461: end_execution_reason_t parse_execution_context_t::run_for_statement(const ast::for_header_t&, const ast::job_list_t&): Assertion `retval == ENV_OK' failed.

because this used the wrong way to see if something is read-only.
This commit is contained in:
Fabian Homborg 2021-07-30 15:28:02 +02:00
parent 55732f445a
commit dd3cdbcfc9
2 changed files with 9 additions and 1 deletions

View File

@ -447,7 +447,7 @@ end_execution_reason_t parse_execution_context_t::run_for_statement(
}
auto var = parser->vars().get(for_var_name, ENV_DEFAULT);
if (var && var->read_only()) {
if (env_var_t::flags_for(for_var_name.c_str()) & env_var_t::flag_read_only) {
return report_error(STATUS_INVALID_ARGS, header.var_name,
L"You cannot use read-only variable '%ls' in a for loop",
for_var_name.c_str());

View File

@ -500,3 +500,11 @@ echo banana
# This used to be a parse error - #7685.
echo (echo hello\\)
# CHECK: hello\
# Should fail because $PWD is read-only.
for PWD in foo bar
true
end
# CHECKERR: {{.*}}/basic.fish (line {{\d+}}): You cannot use read-only variable 'PWD' in a for loop
# CHECKERR: for PWD in foo bar
# CHECKERR: ^