nushell / nushell/new-nu-parser

Prevent parent scope symbols leaking into module's scope

Open
#7 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
34
Forks
11
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing scope-stack symbol lookup and create_default_context(), then inspect how FrameType and constants such as NU_LIB_DIRS are represented. Decide how Barrier and Prelude frames should interact with module isolation, default commands, and nupm overlays. Done means the lookup rules and NU_LIB_DIRS behavior are specified and implemented with coverage for parent symbols, prelude commands, and module imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.