Skip to content

Conversation

@WindSoilder
Copy link
Contributor

Description

While reviewing #14388, I think we can make some improvement on parser.

For the following code:

let a = 3
a = 10   # should be error
$a = 10 # another error

I think they can raise ParseError, so nushell doesn't need to move forward compiling IR block.

User-Facing Changes

let a = 3
a = 10

Will raise parse error instead of compile error.

Tests + Formatting

Added 1 test.

@fdncred
Copy link
Contributor

fdncred commented Nov 21, 2024

At one point we were trying to decide whether a or $a was appropriate and decided to leave them both. I think it's better to allow only $a like you've demonstrated above.

@WindSoilder
Copy link
Contributor Author

WindSoilder commented Nov 21, 2024

The real issue here is not the usage of variable a through a or $a, but try to mutate a variable which is not mutable.

Copy link
Contributor

@devyn devyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small change :) I think it's a good idea

#[error("Assignment to an immutable variable.")]
#[diagnostic(
code(nu::parser::assignment_requires_mutable_variable),
help("declare the variable with `mut`, or shadow it again with `let`")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like the help

@WindSoilder WindSoilder requested a review from devyn November 26, 2024 02:22
@sholderbach
Copy link
Member

Great error messages!

@sholderbach sholderbach merged commit 8178309 into nushell:main Nov 29, 2024
13 checks passed
@github-actions github-actions bot added this to the v0.101.0 milestone Nov 29, 2024
@fdncred fdncred added the deprecated:pr-errors Deprecated: use A:error-handling, A:error-unhelpful, or A:error-silent-fail instead label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deprecated:pr-errors Deprecated: use A:error-handling, A:error-unhelpful, or A:error-silent-fail instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants