mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 12:15:42 +02:00
raise ParseError if assign to a non-variable or non-mutable-variable (#14405)
# Description While reviewing #14388, I think we can make some improvement on parser. For the following code: ```nushell 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 ```nushell let a = 3 a = 10 ``` Will raise parse error instead of compile error. # Tests + Formatting Added 1 test.
This commit is contained in:
@ -148,3 +148,14 @@ fn def_should_not_mutate_mut() {
|
||||
assert!(actual.err.contains("capture of mutable variable"));
|
||||
assert!(!actual.status.success())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn assign_to_non_mut_variable_raises_parse_error() {
|
||||
let actual = nu!("let x = 3; $x = 4");
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("parser::assignment_requires_mutable_variable"));
|
||||
|
||||
let actual = nu!("mut x = 3; x = 5");
|
||||
assert!(actual.err.contains("parser::assignment_requires_variable"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user