Skip to content

Fixed the panic when type a statement similar to let f = 'f' $ in the nushell#9851

Merged
sophiajt merged 3 commits intonushell:mainfrom
mengsuenyan:fix/9826
Aug 1, 2023
Merged

Fixed the panic when type a statement similar to let f = 'f' $ in the nushell#9851
sophiajt merged 3 commits intonushell:mainfrom
mengsuenyan:fix/9826

Conversation

@mengsuenyan
Copy link
Copy Markdown
Contributor

@mengsuenyan mengsuenyan commented Jul 29, 2023

fixed the following bugs:

# type following statements in the nushell
let f = 'f' $;
mut f = 'f' $;
const f = 'f' $;

# then remove variable f, it will panics
let = 'f' $;
mut  = 'f' $;
const = 'f' $;

@mengsuenyan mengsuenyan changed the title Fix/9826 panic when let no var Fixed the panic when type like let f = 'f' $ in the nushell Jul 29, 2023
@mengsuenyan mengsuenyan changed the title Fixed the panic when type like let f = 'f' $ in the nushell Fixed the panic when type statement similar to let f = 'f' $ in the nushell Jul 29, 2023
@mengsuenyan mengsuenyan changed the title Fixed the panic when type statement similar to let f = 'f' $ in the nushell Fixed the panic when type a statement similar to let f = 'f' $ in the nushell Jul 29, 2023
@sophiajt
Copy link
Copy Markdown
Contributor

Can you add tests to this to ensure it's working?

@sophiajt
Copy link
Copy Markdown
Contributor

sophiajt commented Aug 1, 2023

thanks!

@sophiajt sophiajt merged commit fea8227 into nushell:main Aug 1, 2023
WindSoilder pushed a commit that referenced this pull request Sep 27, 2024
# Description
Old code was comparing remaining positional arguments with total number
of arguments, where it should've compared remaining positional with
with remaining arguments of any kind. This means that if a function was
given too few arguments, `calculate_end_span` would believe that it
actually had too many arguments, since after parsing the first few
arguments, the number of remaining arguments needed were fewer than the
*total* number of arguments, of which we had used several.

Fixes #9072
Fixes: #13930
Fixes: #12069
Fixes: #8385

Extracted from #10381

## Bonus

It also improves the error handling on missing positional arguments
before keywords (no longer crashing since #9851). Instead of just giving
the keyword to the parser for the missing positional, we give an
explicit error about a missing positional argument. I would like better
descriptions than "missing var_name" though, but I'm not sure if that's
available without

Old error
```
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #1:1:1]
 1 │ let = if foo
   ·     ┬
   ·     ╰── expected valid variable name
   ╰────
```

New error
```
Error: nu::parser::missing_positional

  × Missing required positional argument.
   ╭─[entry #18:1:1]
 1 │ let = foo
   ·    ┬
   ·    ╰── missing var_name
   ╰────
  help: Usage: let <var_name> = <initial_value>
```

# User-Facing Changes
The program `alias = = =` is no longer accepted by the parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in parser when backspacing over variable name nushell panics if I type let = if $

2 participants