Skip to content

use path item1 item2 syntax isn't prohibited, but item2 isn't brought into scope #11143

@Veetaha

Description

@Veetaha

Describe the bug

The use command allows one to write use path item1 item2, in which case only item1 is brought into scope but item2 is ignored.

This problem repeats with item3 item4 and so on as well.

Static type checking passes and an error is reported at runtime that "executable was not found" for item2 usage.

Btw, item2 and the other trailing arguments of use aren't validated at all. I can write any string in place of item2 even if it doesn't identify any item from the used path module. It looks like those arguments are just ignored.

Instead, according to use's --help if you want to import multiple items you need to enclose them in [].

How to reproduce

To reproduce this bug you should have two script files. Beware that only this way you get a poor error message. If you define everything in one file nushell suggests that the command exists in another module and could be imported.

# x.nu

use lib.nu *

# Just an empty main to make nu CLI builder happy
def main [] {}
# lib.nu

module other {
    export def bar [] { 'bar' }
    export def baz [] { 'baz' }
}

use other bar baz

export def 'main foo' [] {
    echo (bar)
    echo (baz)
}

Then run the following command:

nu x.nu foo

You'll see the output like this:

bar
Error: nu::shell::external_command

  × External command failed
    ╭─[/home/veetaha/sandbox/nu/lib.nu:9:1]
  9 │     echo (bar)
 10 │     echo (baz)
    ·           ─┬─
    ·            ╰── executable was not found
 11 │ }
    ╰────
  help: No such file or directory (os error 2)

Expected behavior

Nushell should either prohibit use path item1 item2 ... syntax and give a clear error message that the item2 wasn't expected, or it should support such syntax and just bring item2 and all other space-separated items into scope.

Screenshots

No response

Configuration

key value
version 0.87.0
branch
commit_hash 77a1c3c
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.71.1 (eb26296b5 2023-08-03)
rust_channel 1.71.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.71.1 (7f1d04c00 2023-07-29)
build_time 2023-11-14 20:57:57 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, static-link-openssl, trash, which, zip
installed_plugins from eml, from ics, from ini, from vcf

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:modulesIssues related to functionality of the module system. See also usage:modulescategory:bugSomething isn't workingstatus:needs-triageAn issue that hasn't had any proper look

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions