Fix result after explicit return in a while block

Closes #5513.
This commit is contained in:
Mahmoud Al-Qudsi 2019-01-13 18:56:19 -06:00
parent 2fdcc4544a
commit 027fc43736

View File

@ -575,9 +575,14 @@ parse_execution_result_t parse_execution_context_t::run_while_statement(
}
}
// $status after `while` should be 0 if it executed at least once, otherwise the last `$status`
// obtained by executing the condition is preserved. See #4982.
if (loop_executed) {
// Do not override status if exiting due to the presence of an explict `return xxx` (#5513)
if (!associated_block->skip) {
proc_set_last_status(STATUS_CMD_OK);
}
}
return ret;
}