Skip to content

Schrodinger's continue works but doesn't #8878

@ghost

Description

Describe the bug

> [1,2,3] | each { |x|
:::   if $x == 2 {
:::     continue
:::   }
:::   print -e $x
::: }
1
3
Error: nu::shell::eval_block_with_input

  × Eval block failed with pipeline input
   ╭─[entry #1:1:1]
 1 │ [1,2,3] | each { |x|
   ·    ┬
   ·    ╰── source value
 2 │   if $x == 2 {
   ╰────

Error:
  × Continue used outside of loop
   ╭─[entry #1:2:1]
 2 │   if $x == 2 {
 3 │     continue
   ·     ────┬───
   ·         ╰── used outside of loop
 4 │   }
   ╰────

13 is printed as expected, and then the script also fails on continue. So it's like continue worked... but didn't.

How to reproduce

See above

Expected behavior

Either not work at all (don't run the cycle) and fail-fast on detecting continue in an invalid location, or just work normally and don't error out.

Or, if this thing cannot be statically checked (but Nu does static checking according to docs), I would expect it to print 1, and then fail on continue. But it gets to 3! Magic.

Screenshots

No response

Configuration

key value
version 0.78.0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.68.0 (2c8cc3432 2023-03-06)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.68.0 (115f34552 2023-02-26)
build_time 2023-04-13 17:17:32 +02:00
build_rust_channel release
features default, zip
installed_plugins

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions