Skip to content

Parser crashes when variable name in let expression is missing #10380

@anka-213

Description

@anka-213

Describe the bug

I get index out of bounds crash when typing a program like this:

let = a | b

I ran into this when trying to rename a variable

How to reproduce

  1. Launch nu
  2. Write let = a | b in the terminal
  3. nu immediately crashes

Expected behavior

I expect the parser to not be partial or at least that any panic from the parser would be caught instead of crashing the full shell.

Screenshots

No response

Configuration

key value
version 0.83.1
branch
commit_hash
build_os macos-x86_64
build_target x86_64-apple-darwin
rust_version rustc 1.71.1 (eb26296b5 2023-08-03) (built from a source tarball)
cargo_version cargo 1.71.1
build_time 1980-01-01 00:00:00 +00:00
build_rust_channel release
allocator standard
features default, sqlite, trash, which, zip
installed_plugins

Additional context

Stack trace:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', crates/nu-parser/src/parser.rs:3068:47                                                             09/15/2023 10:50:32 AM
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: nu_parser::parser::parse_var_with_opt_type
   4: nu_parser::parse_keywords::parse_let
   5: nu_parser::parser::parse_builtin_commands
   6: nu_parser::parser::parse_block
   7: nu_parser::parser::parse
   8: <nu_cli::syntax_highlight::NuHighlighter as reedline::highlighter::Highlighter>::highlight
   9: reedline::engine::Reedline::repaint
  10: reedline::engine::Reedline::read_line
  11: nu_cli::repl::evaluate_repl
  12: nu::run::run_repl
  13: nu::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:needs-triageAn issue that hasn't had any proper look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions