Skip to content

Schrodinger's continue works but doesn't #8878

Closed

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

Activity

  1. sophiajt commented on Apr 14, 2023

    @sophiajt
    Contributor

    Looks like each doesn't support continue, yet. In theory, you can add it where each supports break now.

  2. added
    category:inconsistent-behavior
    on Apr 14, 2023
  3. added a commit that references this issue on Apr 15, 2023
    fff4de5
  4. added this to the v0.79.0 milestone on Apr 15, 2023
  5. added a commit that references this issue on Apr 15, 2023
    8e2fb7f
  6. amalagaura commented on May 23, 2025

    @amalagaura

    I am running 0.104.0 and this is still throwing an error on the test case in the PR. I am confused because this PR shows merged:

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:inconsistent-behaviorgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions