Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loop { echo foo } doesn't work #7402

Closed
Veetaha opened this issue Dec 9, 2022 · 1 comment · Fixed by #7433
Closed

loop { echo foo } doesn't work #7402

Veetaha opened this issue Dec 9, 2022 · 1 comment · Fixed by #7433
Labels
semantics Places where we should define/clarify nushell's semantics
Milestone

Comments

@Veetaha
Copy link

Veetaha commented Dec 9, 2022

Describe the bug

Minimal reproduction.

loop {
    echo foo
}

How to reproduce

Run the script higher and you'll see that the program hangs as expected, but doesn't produce any output to the terminal.

Expected behavior

I expect to see the following output repeating forever:

foo
foo
foo
foo

Configuration

Also, this doesn't work

key value
version 0.72.2
branch main
commit_hash b39d797
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.65.0 (897e37553 2022-11-02)
rust_channel 1.65.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.65.0 (4bc8f24d3 2022-10-20)
pkg_version 0.72.2
build_time 2022-12-09 03:39:32 +01:00
build_rust_channel release
features database, default, trash, which, zip
installed_plugins

Additional Context

The problem also appears with while true:

while true {
    echo foo
}

And it also appears with for:

for _ in (seq 10) {
     echo foo
}
@Veetaha Veetaha changed the title loop with try catch inside skips catch block loop/while with try catch inside skips catch block Dec 9, 2022
@Veetaha
Copy link
Author

Veetaha commented Dec 9, 2022

UPD
The original issue was created on 0.72.1 version of nu, where the problem was with try/catch inside of the loop, where the following didn't produce any output:

loop {
    try {
        ^false
    } catch { }
    
    print "err"
}

But it seems it is fixed now, however, the code in the issue doesn't work as expected

@Veetaha Veetaha changed the title loop/while with try catch inside skips catch block loop { "echo" } doesn't work Dec 9, 2022
@Veetaha Veetaha changed the title loop { "echo" } doesn't work loop { echo "foo" } doesn't work Dec 9, 2022
@Veetaha Veetaha changed the title loop { echo "foo" } doesn't work loop { echo foo } doesn't work Dec 9, 2022
@sholderbach sholderbach added the semantics Places where we should define/clarify nushell's semantics label Dec 9, 2022
sophiajt pushed a commit that referenced this issue Dec 11, 2022
# Description

Fixes: #7404 
Fixes: #7402 

## About change
In `eval_block`, all pipelines(or called statements?) result will be
printed except the last one, the last one is returned by `eval_block`
function.

So if we want to print the last statement in eval block, we just need to
print that value.

# User-Facing Changes

### for
```
❯ for _ in 1..2 { echo "a" }
a
a
```

### while
```
❯ mut x = 1; while $x < 3 { $x = $x + 1; echo bb; }
bb
bb
```

### loop
```
❯ mut total = 0; loop {
∙     if $total > 1 {
∙         break
∙     } else {
∙         $total += 1
∙     }
∙     echo 3
∙ }
3
3
```

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
  - `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
@hustcer hustcer added this to the v0.73 milestone Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semantics Places where we should define/clarify nushell's semantics
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants