diff --git a/parse_execution.cpp b/parse_execution.cpp index 8a2e9d271..46df733ce 100644 --- a/parse_execution.cpp +++ b/parse_execution.cpp @@ -547,13 +547,15 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p _(L"switch: Expected exactly one argument, got %lu\n"), switch_values_expanded.size()); } - const wcstring &switch_value_expanded = switch_values_expanded.at(0).completion; - - switch_block_t *sb = new switch_block_t(); - parser->push_block(sb); - + if (result == parse_execution_success) { + const wcstring &switch_value_expanded = switch_values_expanded.at(0).completion; + + switch_block_t *sb = new switch_block_t(); + parser->push_block(sb); + + /* Expand case statements */ const parse_node_t *case_item_list = get_child(statement, 3, symbol_case_item_list); @@ -597,16 +599,16 @@ parse_execution_result_t parse_execution_context_t::run_switch_statement(const p } } } - } - if (result == parse_execution_success && matching_case_item != NULL) - { - /* Success, evaluate the job list */ - const parse_node_t *job_list = get_child(*matching_case_item, 3, symbol_job_list); - result = this->run_job_list(*job_list, sb); - } + if (result == parse_execution_success && matching_case_item != NULL) + { + /* Success, evaluate the job list */ + const parse_node_t *job_list = get_child(*matching_case_item, 3, symbol_job_list); + result = this->run_job_list(*job_list, sb); + } - parser->pop_block(sb); + parser->pop_block(sb); + } return result; }