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

let and mut panic if tokens are placed after a redirection #13835

Closed
1Kinoti opened this issue Sep 12, 2024 · 1 comment · Fixed by #14035
Closed

let and mut panic if tokens are placed after a redirection #13835

1Kinoti opened this issue Sep 12, 2024 · 1 comment · Fixed by #14035
Labels
🐛 bug Something isn't working panic parser Issues related to parsing
Milestone

Comments

@1Kinoti
Copy link
Contributor

1Kinoti commented Sep 12, 2024

Describe the bug

let and mut should look like this

let foo = 42
mut bar = 69

If a redirection is placed between the variable name and =, attempting to add another token panics nu

This also happens even if there are type annotations

let foo: int = 42

How to reproduce

  1. Write this in your repl
let foo = 42
# or
mut bar = 69
  1. Move the cursor to anywhere between the variable name and the =
let foo = 42
#      ^
#      |
#      move the cursor here
  1. Add any redirection in the cursor position
let foo o> file.nu = 42
#          -------
#             |
#             immediately after writing 'f', nu panics

Expected behavior

  1. Not panic()!
  2. Accept the redirection keyword and the target, and reject them gracefully later

Configuration

key value
version 0.97.1
major 0
minor 97
patch 1
branch
commit_hash 60769ac
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.78.0 (9b00956e5 2024-04-29)
rust_channel 1.78.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.78.0 (54d8815d0 2024-03-26)
build_time 2024-08-21 03:29:24 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, static-link-openssl, system-clipboard, trash
installed_plugins

Panic message

let foo o> Error:   × Main thread panicked.
  ├─▶ at crates/nu-protocol/src/engine/state_working_set.rs:385:48
  ╰─▶ slice index starts at 15 but ends at 12
  help: set the `RUST_BACKTRACE=1` environment variable to display a backtrace.
@1Kinoti 1Kinoti added the needs-triage An issue that hasn't had any proper look label Sep 12, 2024
@KAAtheWiseGit
Copy link
Contributor

This happens even if you type normally, right at the = character. This is what I get at 5101b5e:

~/fork/nushell> let foo o> file Error:   × Main thread panicked.
  ├─▶ at crates/nu-protocol/src/span.rs:187:9
  ╰─▶ assertion failed: spans.windows(2).all(|spans|
              {
                  let &[a, b] = spans else { return false; };
                  a.start <= b.start && a.end <= b.end
              })
         0: 0x564874f1ad54 - rust_begin_unwind
         1: 0x5648719ec063 - core::panicking::panic_fmt::h556dd313afe3d53e
         2: 0x5648719ec0ec - core::panicking::panic::hac5d0741b9be4a00
         3: 0x5648745a84b0 - nu_protocol::span::Span::concat::h27e6cc6003258db3
                      at /home/kaathewise/fork/nushell/crates/nu-protocol/src/span.rs:187
         4: 0x56487369b5d1 - nu_parser::parse_keywords::parse_let::h942bf08e8d5b2400
                      at /home/kaathewise/fork/nushell/crates/nu-parser/src/parse_keywords.rs:3127
         5: 0x56487370b1a3 - nu_parser::parser::parse_builtin_commands::h0f93e1158d050920
                      at /home/kaathewise/fork/nushell/crates/nu-parser/src/parser.rs:5598
         6: 0x56487370f1e4 - nu_parser::parser::parse_pipeline::h404fb07b7bd0b3a4
                      at /home/kaathewise/fork/nushell/crates/nu-parser/src/parser.rs:5983
         7: 0x56487370f853 - nu_parser::parser::parse_block::h3a794479b0a7fa59
                      at /home/kaathewise/fork/nushell/crates/nu-parser/src/parser.rs:6017
         8: 0x5648737149b1 - nu_parser::parser::parse::h8625e6639ecf9fcf
                      at /home/kaathewise/fork/nushell/crates/nu-parser/src/parser.rs:6565
         9: 0x56487330a1a5 - <nu_cli::syntax_highlight::NuHighlighter as reedline::highlighter::Highlighter>::highlight::h5b073a4b913cb1f8
                      at /home/kaathewise/fork/nushell/crates/nu-cli/src/syntax_highlight.rs:26
        10: 0x56487343080a - reedline::engine::Reedline::buffer_paint::hf271607f81f8033a
                      at /home/kaathewise/.local/state/cargo/git/checkouts/reedline-e42026a78d91c510/7af8959/src/engine.rs:1740
        11: 0x56487342d90b - reedline::engine::Reedline::repaint::hb35f6d4ec72e4c1c
                      at /home/kaathewise/.local/state/cargo/git/checkouts/reedline-e42026a78d91c510/7af8959/src/engine.rs:1505
        12: 0x564873426df9 - reedline::engine::Reedline::read_line_helper::hf0ab89bce4d8be63
                      at /home/kaathewise/.local/state/cargo/git/checkouts/reedline-e42026a78d91c510/7af8959/src/engine.rs:802
        13: 0x564873426120 - reedline::engine::Reedline::read_line::h5b125cba9094a8b8
                      at /home/kaathewise/.local/state/cargo/git/checkouts/reedline-e42026a78d91c510/7af8959/src/engine.rs:646
        14: 0x5648732b55ad - nu_cli::repl::loop_iteration::h6816b17367ca997b
                      at /home/kaathewise/fork/nushell/crates/nu-cli/src/repl.rs:450
        15: 0x5648732a1b82 - nu_cli::repl::evaluate_repl::{{closure}}::hbca2bfde76009799
                      at /home/kaathewise/fork/nushell/crates/nu-cli/src/repl.rs:190
        16: 0x56487325cccf - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h895fb711eb7591ef
                      at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panic/unwind_safe.rs:272
        17: 0x5648732ea4a0 - std::panicking::try::do_call::h1cf869321e89d99f
                      at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:557
        18: 0x5648732d3c2b - __rust_try
        19: 0x5648732d3b6e - std::panicking::try::hc4b39dbf45d3d1c2
                      at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:521
                       - std::panic::catch_unwind::he3bf7de7bdf452cc
                      at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panic.rs:350
        20: 0x5648732ae5aa - nu_cli::repl::evaluate_repl::h65b3e40271ec5dc4
                      at /home/kaathewise/fork/nushell/crates/nu-cli/src/repl.rs:189
        21: 0x564871a4fc28 - nu::run::run_repl::he4323f7bae4513ca
                      at /home/kaathewise/fork/nushell/src/run.rs:208
        22: 0x564871a02fa9 - nu::main::ha6e44a0e5fd8878b
                      at /home/kaathewise/fork/nushell/src/main.rs:416
        23: 0x564871a51d1b - core::ops::function::FnOnce::call_once::hd3df071a50ca3844
                      at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/ops/function.rs:250
  help: set the `RUST_BACKTRACE=1` environment variable to display a backtrace.

@sholderbach sholderbach added 🐛 bug Something isn't working parser Issues related to parsing panic and removed needs-triage An issue that hasn't had any proper look labels Sep 13, 2024
@github-actions github-actions bot added this to the v0.100.0 milestone Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working panic parser Issues related to parsing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants