unify the *-BuiltinVar parser errors (#8944)

# Description

this pr condenses `MutBuiltinVar`, `LetBuiltinVar` and `ConstBuiltinVar`
into one error:
```nu
Error: nu::parser::name_is_builtin_var

  × `in` used as variable name.
   ╭─[entry #69:1:1]
 1 │ let in = 420
   ·     ─┬
   ·      ╰── already a builtin variable
   ╰────
  help: 'in' is the name of a builtin Nushell variable and cannot be used
        as a variable name
```

it also fixes this case which was previously not handled
```nu
let $nu = 420 # this variable would have been 'lost'
```
This commit is contained in:
mike
2023-04-20 20:44:31 +03:00
committed by GitHub
parent d339902dc6
commit fb72da0e82
4 changed files with 40 additions and 29 deletions

View File

@ -1,7 +1,7 @@
use nu_test_support::{nu, pipeline};
#[test]
fn let_parse_error() {
fn let_name_builtin_var() {
let actual = nu!(
cwd: ".", pipeline(
r#"

View File

@ -12,6 +12,34 @@ fn mut_variable() {
assert_eq!(actual.out, "4");
}
#[test]
fn mut_name_builtin_var() {
let actual = nu!(
cwd: ".", pipeline(
r#"
mut in = 3
"#
));
assert!(actual
.err
.contains("'in' is the name of a builtin Nushell variable"));
}
#[test]
fn mut_name_builtin_var_with_dollar() {
let actual = nu!(
cwd: ".", pipeline(
r#"
mut $env = 3
"#
));
assert!(actual
.err
.contains("'env' is the name of a builtin Nushell variable"))
}
#[test]
fn mut_variable_in_loop() {
let actual = nu!(