fix error when exporting consts with type signatures in modules (#14118)

Fixes #14023

# Description

- Prevents "failed to find added variable" when modules export constants
  with type signatures:

```nushell
> module foo { export const bar: int = 2 }
Error: nu::parser::unknown_state

  × Internal error.
   ╭─[entry #1:1:21]
 1 │ module foo { export const bar: int = 2 }
   ·                     ─────────┬────────
   ·                              ╰── failed to find added variable
```

- Returns `name_is_builtin_var` errors for names with type signatures:

```nushell
> let env: string = "";
Error: nu::parser::name_is_builtin_var

  × `env` used as variable name.
   ╭─[entry #1:1:5]
 1 │ let env: string = "";
   ·     ─┬─
   ·      ╰── already a builtin variable
```
This commit is contained in:
Solomon
2024-10-22 09:54:31 +00:00
committed by GitHub
parent ee97c00818
commit 4968b6b9d0
5 changed files with 53 additions and 43 deletions

View File

@ -1,10 +1,11 @@
use nu_test_support::nu;
use rstest::rstest;
#[test]
fn let_name_builtin_var() {
let actual = nu!("let in = 3");
assert!(actual
#[rstest]
#[case("let in = 3")]
#[case("let in: int = 3")]
fn let_name_builtin_var(#[case] assignment: &str) {
assert!(nu!(assignment)
.err
.contains("'in' is the name of a builtin Nushell variable"));
}

View File

@ -1,4 +1,5 @@
use nu_test_support::nu;
use rstest::rstest;
#[test]
fn mut_variable() {
@ -7,11 +8,11 @@ fn mut_variable() {
assert_eq!(actual.out, "4");
}
#[test]
fn mut_name_builtin_var() {
let actual = nu!("mut in = 3");
assert!(actual
#[rstest]
#[case("mut in = 3")]
#[case("mut in: int = 3")]
fn mut_name_builtin_var(#[case] assignment: &str) {
assert!(nu!(assignment)
.err
.contains("'in' is the name of a builtin Nushell variable"));
}