Error on use path item1 item2, if item1 is not a module (#11183)

# Description
Fixes: #11143

# User-Facing Changes
Take the following as example:
```nushell
module foo { export def bar [] {}; export def baz [] {} }
```

`use foo bar baz` will be error:
```
❯ use foo c d
Error: nu::parser::wrong_import_pattern

  × Wrong import pattern structure.
   ╭─[entry #2:1:1]
 1 │ use foo c d
   ·           ┬
   ·           ╰── Trying to import something but the parent `c` is not a module, maybe you want to try `use <module> [<name1>, <name2>]`
   ╰────
```

# Tests + Formatting
Done
This commit is contained in:
WindSoilder
2023-12-05 18:38:45 +08:00
committed by GitHub
parent 2ffe30ecf0
commit fb3350ebc3
4 changed files with 47 additions and 13 deletions

View File

@ -296,3 +296,18 @@ fn use_main_not_exported() {
assert!(actual.err.contains("external_command"));
}
#[test]
fn use_sub_subname_error_if_not_from_submodule() {
let inp = r#"module spam { export def foo [] {}; export def bar [] {} }; use spam foo bar"#;
let actual = nu!(inp);
assert!(actual.err.contains("try `use <module> [<name1>, <name2>]`"))
}
#[test]
fn can_use_sub_subname_from_submodule() {
let inp =
r#"module spam { export module foo { export def bar [] {"bar"} } }; use spam foo bar; bar"#;
let actual = nu!(inp);
assert_eq!(actual.out, "bar")
}