Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe bug regarding overriding built in commands in a shared module space #15315

Open
DavidTelenko opened this issue Mar 14, 2025 · 1 comment
Labels
modules question the issue author asks something scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound

Comments

@DavidTelenko
Copy link

DavidTelenko commented Mar 14, 2025

Question

Let say i have two modules

# modules/moduleA.nu
export def hello [--period: duration] { sleep $period; echo "hello from moduleB" }
# modules/moduleB.nu
use moduleA.nu *
export def sleep [] { echo "hello from moduleA" }

And a global config.nu file

# config.nu
const nushellDir = ($nu.config-path | path parse).parent
const modules = ([$nushellDir, modules] | path join)
use $modules *

This results in a similar error:

  × Extra positional argument.
    ╭─[modules/moduleA.nu:1]
  1 │         sleep $period
    ·               ───┬───
    ·                  ╰── extra positional argument

Apparently all modules are loaded in the same space, as some sort of lookbehind occurs for modules and it overrides built-ins with custom commands.

Am I doing something incorrectly here? What I initially assumed is that if I import one module into another the target of the import should not affect the logic of the imported module.

Note

I'm quite unexperienced with nushell behavior as a programming language so sorry if all of this is nonsense

Additional context and details

  • OS: Windows
  • Nushell Version: 0.102.0
@DavidTelenko DavidTelenko added the question the issue author asks something label Mar 14, 2025
@DavidTelenko DavidTelenko changed the title Maybe bug regarding overriding built in commands Maybe bug regarding overriding built in commands in a shared module space Mar 14, 2025
@sholderbach sholderbach added modules scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound labels Mar 16, 2025
@sholderbach
Copy link
Member

Gotta admit that I am not fully up to speed on the name resolution behavior in modules.

But by just looking at your code, I am not sure if the sleep is shadowed by the use moduleA.nu * in moduleB.nu or by the glob import in your config.nu (so that moduleA's sleep already shadowed the builtin, when moduleB got to parsing.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules question the issue author asks something scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound
Projects
None yet
Development

No branches or pull requests

2 participants