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

function body uses variable which out of scope #9746

Closed
WindSoilder opened this issue Jul 20, 2023 · 2 comments
Closed

function body uses variable which out of scope #9746

WindSoilder opened this issue Jul 20, 2023 · 2 comments
Labels
needs-triage An issue that hasn't had any proper look scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound
Milestone

Comments

@WindSoilder
Copy link
Collaborator

Describe the bug

Continue from comment: #9724 (comment)

How to reproduce

Run the following code in repl or script

let b = 3
def c [] { echo $b }
c

It outputs 3

Expected behavior

I expected nu to returns error which says that $b is not found

Screenshots

No response

Configuration

key value
version 0.82.1
branch nightly
commit_hash bd00328
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.68.2 (9eb3afe9e 2023-03-27)
rust_channel 1.68.2-x86_64-unknown-linux-gnu
cargo_version cargo 1.68.2 (6feb7c9cf 2023-03-26)
build_time 2023-07-12 02:15:14 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, static-link-openssl, trash, which, zip
installed_plugins

Additional context

The following works as expected, although the error message is not fine.

 do { 
    let b = 3
    def c [] { echo $b }
    c 
 }
@WindSoilder WindSoilder added the needs-triage An issue that hasn't had any proper look label Jul 20, 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 20, 2023
@sophiajt
Copy link
Contributor

After discussing with folks during the Nushell meeting, it looks like the system does allow def to close over variables. Your examples should work.

I've fixed the do case in #9764

@WindSoilder
Copy link
Collaborator Author

Ok, so I'd closing this

@hustcer hustcer added this to the v0.83.0 milestone Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage An issue that hasn't had any proper look 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

4 participants