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

[Overlay] Possible regression in overlay use, variable remains active after overlay hide command #14739

Open
GrabbenD opened this issue Jan 3, 2025 · 2 comments
Labels
🐛 bug Something isn't working modules parser Issues related to parsing

Comments

@GrabbenD
Copy link

GrabbenD commented Jan 3, 2025

Describe the bug

cc: @kubouch

Affected pages

Problem

The book suggests that any new definition will be inaccessible after hiding a overlay as seen here:

Any new definition (command, alias, environment variable) is recorded into the last active overlay:

overlay use spam
def eggs [] { "eggs" }

Now, the eggs command belongs to the spam overlay. If we remove the overlay, we can't call it anymore:

overlay hide spam
eggs

However, that's not the case after hiding the overlay in the following script:

How to reproduce

$ nu script.nu

#!/usr/bin/env nu

def main [] {
  module spam { export def foo [] { "foo" } }
  overlay use spam
  def bar [] { "bar" }
  overlay hide spam
  bar # Returns bar
}

Edit: 2nd reproducible example in #2 comment: #14739 (comment)

Expected behavior

Any definitions after overlay use, like def bar in the reproducible example, should become inaccessible after overlay hide.

Configuration

$ version | transpose key value | to md --pretty

| key                | value                                                            |
| ------------------ | ---------------------------------------------------------------- |
| version            | 0.101.0                                                          |
| major              | 0                                                                |
| minor              | 101                                                              |
| patch              | 0                                                                |
| branch             | makepkg                                                          |
| commit_hash        | fb2610904997f54f50ad52095948bede81695f31                         |
| build_os           | linux-x86_64                                                     |
| build_target       | x86_64-unknown-linux-gnu                                         |
| rust_version       | rustc 1.83.0 (90b35a623 2024-11-26) (Arch Linux rust 1:1.83.0-1) |
| cargo_version      | cargo 1.83.0 (5ffbef321 2024-10-29)                              |
| build_time         | 2024-12-23 06:13:49 +00:00                                       |
| build_rust_channel | release                                                          |
| allocator          | mimalloc                                                         |
| features           | default, sqlite, trash                                           |
| installed_plugins  |                                                                  |

$ sys host

╭─────────────────┬────────────────────╮
│ name            │ Arch Linux         │
│ long_os_version │ Linux  Arch Linux  │
│ kernel_version  │ 6.9.8-273-tkg-bore │
│ hostname        │ archlinux          │
│ uptime          │ 3hr 59min 49sec    │
│ boot_time       │ 3 hours ago        │
╰─────────────────┴────────────────────╯
@GrabbenD GrabbenD added the needs-triage An issue that hasn't had any proper look label Jan 3, 2025
@GrabbenD
Copy link
Author

GrabbenD commented Jan 3, 2025

The following code snippet is not affected by this bug:

#!/usr/bin/env nu

#def main [] {
module spam { export def foo [] { "foo" } }
overlay use spam
def bar [] { "bar" }
overlay hide spam
bar # Error (correct behavior)
#}

Turns out, this is only reproducible inside functions Edit: see below

@GrabbenD
Copy link
Author

GrabbenD commented Jan 4, 2025

Found another reproducible example

It's possible to trigger this bug by first declaring a function in the global scope (like def something) which triggers def bar to believe it belongs to the global scope even though it's defined after overlay use. Example:

#!/usr/bin/env nu

def something [] { "example" }

module spam {}
overlay use spam
def bar [] { "bar" }
overlay hide spam
bar # Returns bar

Workaround

Define modules in global space first:

#!/usr/bin/env nu

module spam {}

def main [] {
  overlay use spam
  def bar [] { "bar" }
  overlay hide spam
  bar # Error (correct behavior)
}

@kubouch kubouch added 🐛 bug Something isn't working parser Issues related to parsing modules and removed needs-triage An issue that hasn't had any proper look labels Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working modules parser Issues related to parsing
Projects
None yet
Development

No branches or pull requests

2 participants