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

Variable not captured correctly #5994

Open
kubouch opened this issue Jul 8, 2022 · 1 comment · Fixed by #6309
Open

Variable not captured correctly #5994

kubouch opened this issue Jul 8, 2022 · 1 comment · Fixed by #6309
Labels
🐛 bug Something isn't working hooks Hooks are used to react to changes during interactive execution scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound

Comments

@kubouch
Copy link
Contributor

kubouch commented Jul 8, 2022

Describe the bug

It seems like in some tricky cases the variables are not captured correctly.

How to reproduce

Create a .nu-env file with the following contents:

def-env hook-shell [n: string] {
    let-env config = ($env.config | upsert hooks.env_change.NUSHELL_CURRENT_SHELL {
        [
            { let-env FOO = $n }
        ]
    })
}

hook-shell $env.NUSHELL_CURRENT_SHELL

Then:

> $env.NUSHELL_CURRENT_SHELL = 'foo'
> source .nu-env
Error: nu::shell::variable_not_found (link)

  × Variable not found
   ╭─[.nu-env:3:1]
 3 │         [
 4 │             { let-env FOO = $n }
   ·                             ─┬
   ·                              ╰── variable not found
 5 │         ]
   ╰────

Expected behavior

I would expect the $n variable to be captured from the argument of hook-shell and equal to the $env.NUSHELL_CURRENT_SHELL.

Screenshots

No response

Configuration

key value
version 0.65.1
branch hooks_string
commit_hash eac5f62
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.62.0 (a8314ef7d 2022-06-27)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.62.0 (a748cf5a3 2022-06-08)
pkg_version 0.65.1
build_time 2022-07-07 20:10:14 +03:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins gstat

Additional context

No response

@kubouch kubouch added the 🐛 bug Something isn't working label Jul 8, 2022
@hustcer hustcer added this to the v0.67.0 milestone Aug 12, 2022
@kubouch
Copy link
Contributor Author

kubouch commented Aug 13, 2022

Oh, oops, this is not meant to be closed. The error might be in the parser collecting the captures, I'm not sure.

@kubouch kubouch reopened this Aug 13, 2022
@hustcer hustcer modified the milestones: v0.67.0, v0.68.0 Aug 17, 2022
@hustcer hustcer removed this from the v0.68.0 milestone Sep 4, 2022
@sholderbach sholderbach added the hooks Hooks are used to react to changes during interactive execution label Sep 5, 2022
@github-actions github-actions bot added the Stale used for marking issues and prs as stale label Jan 18, 2023
@kubouch kubouch removed the Stale used for marking issues and prs as stale label Jul 18, 2023
@sholderbach sholderbach added the scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working hooks Hooks are used to react to changes during interactive execution scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants