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

Prevent parent scope symbols leaking into module's scope #7

Open
kubouch opened this issue Aug 18, 2024 · 0 comments
Open

Prevent parent scope symbols leaking into module's scope #7

kubouch opened this issue Aug 18, 2024 · 0 comments

Comments

@kubouch
Copy link
Collaborator

kubouch commented Aug 18, 2024

Leaking user-defined symbols from a parent scope to a module's scope can lead to subtle bugs. The module's scope should be as isolated from the parent scope as possible, but not completely (e.g., we still need basic Nushell commands like ls to be visible).

Could be partially addressed by introducing two new FrameTypes:

  • Barrier: Stops symbol lookup when traversing the scope stack. This prevents the symbol lookup from searching the parent scopes.
  • Prelude: With only Barrier, we'd lose “default” commands that we want to be visible (like ls). Perhaps we could have a Prelude frame type which would get initialized first during create_default_context() with these default commands.

The question is what to do with constants like NU_LIB_DIRS, e.g.,:

const NU_LIB_DIRS = $NU_LIB_DIRS | append '/home/spam/foo`

module {
    use bar.nu  # should it look for 'bar.nu' in '/home/spam/foo'?
}

We might want to decide on this based on the envisioned functionality of how nupm is supposed to use overlays as “virtual environments”, relying on modifying the NU_LIB_DIRS constant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant