mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-20 02:52:46 +08:00
Revert "break/continue: Stop checking if it's in a loop again"
This reverts commit 61cd05efb0
.
It is true that we detect break and continue errors statically, but they can
still be invoked dynamically, example:
set sneaky break
$sneaky # dynamically breaks from the loop
or just `eval break`.
A followup commit will add tests for this.
This commit is contained in:
parent
61cd05efb0
commit
cb79548c49
|
@ -270,6 +270,21 @@ static maybe_t<int> builtin_break_continue(parser_t &parser, io_streams_t &strea
|
||||||
return STATUS_INVALID_ARGS;
|
return STATUS_INVALID_ARGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paranoia: ensure we have a real loop.
|
||||||
|
bool has_loop = false;
|
||||||
|
for (const auto &b : parser.blocks()) {
|
||||||
|
if (b.type() == block_type_t::while_block || b.type() == block_type_t::for_block) {
|
||||||
|
has_loop = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (b.is_function_call()) break;
|
||||||
|
}
|
||||||
|
if (!has_loop) {
|
||||||
|
wcstring error_message = format_string(_(L"%ls: Not inside of loop\n"), argv[0]);
|
||||||
|
builtin_print_help(parser, streams, argv[0], &error_message);
|
||||||
|
return STATUS_CMD_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
// Mark the status in the libdata.
|
// Mark the status in the libdata.
|
||||||
parser.libdata().loop_status = is_break ? loop_status_t::breaks : loop_status_t::continues;
|
parser.libdata().loop_status = is_break ? loop_status_t::breaks : loop_status_t::continues;
|
||||||
return STATUS_CMD_OK;
|
return STATUS_CMD_OK;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user