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

$env assignment silently runs wrong command #9599

Closed
amtoine opened this issue Jul 3, 2023 · 5 comments
Closed

$env assignment silently runs wrong command #9599

amtoine opened this issue Jul 3, 2023 · 5 comments
Labels
inconsistent-behavior Behavior between different commands or types inconsistent/unexpected syntax Changes to the grammar or syntax beyond parser bugfixes

Comments

@amtoine
Copy link
Member

amtoine commented Jul 3, 2023

Describe the bug

related to #9589

i was playing with variable assignment with the new #9589 feature and i think i noticed a pretty bad silent bug 🤔

  1. this is fine because Let with pipeline #9589 did not address assignment
> $env.foo = ls | where type == file
Error: nu::shell::only_supports_this_input_type

  × Input type not supported.
   ╭─[entry #29:1:1]
 1  $env.foo = ls | where type == file
   · ──┬─            ──┬──
   ·                  ╰── only list, binary, raw data or range input data is supported
   ·   ╰── input type: nothing
   ╰────

the error is a bit unhelpful but it's easily fixed by adding parentheses: $env.foo = (ls | where type == file)

  1. this fails because we do not support the syntax as it might be ambiguous inside a record
> export-env { load-env { $env.FOO: ls | where type == file } }
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #31:1:1]
 1  export-env { load-env { $env.FOO: ls | where type == file } }
   ·                       ──────────────────┬──────────────────
   ·                                         ╰── expected record
   ╰────
  1. however, the following does work in the sense in does not throw an error... but i think it does not make any sense here to have $env.FOO being equal to the "ls" string, without any error
> export-env { $env.FOO = ls | where type == file }; $env.FOO
ls

How to reproduce

  1. run export-env { $env.FOO = ls | where type == file }; $env.FOO
  2. see that it gives ls

Expected behavior

i expected export-env { $env.FOO = ls | where type == file } to either

  • give an error just as $env.FOO = ls | where type == file does
  • give the result of ls | where type == file inside $env.FOO

Screenshots

No response

Configuration

key value
version 0.82.1
branch main
commit_hash 2bb0c1c
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-03 18:32:11 +02:00
build_rust_channel release
allocator standard
features default, sqlite, trash, which, zip
installed_plugins hist, plot

Additional context

No response

@amtoine amtoine added the needs-triage An issue that hasn't had any proper look label Jul 3, 2023
@WindSoilder
Copy link
Collaborator

Actually I think it's better to wrap the ls | where type == file with () to make it more readable.

@amtoine
Copy link
Member Author

amtoine commented Jul 11, 2023

Actually I think it's better to wrap the ls | where type == file with () to make it more readable.

mm i dunno.
the syntax has been relaxed in #9589 and i think it's great not being forced to use parentheses for such simple pipes 😋

and because the syntax has been relaxed in that area, i think this behaviour above is a bug and a pretty nasty one 🤔

@amtoine
Copy link
Member Author

amtoine commented Jul 11, 2023

i mean if we allow writing things like something = foo | bar | baz it should always mean that something, either through let or $env., will be able to foo | bar | baz not the string "foo" 🤔

@sholderbach sholderbach added inconsistent-behavior Behavior between different commands or types inconsistent/unexpected syntax Changes to the grammar or syntax beyond parser bugfixes and removed needs-triage An issue that hasn't had any proper look labels Jul 11, 2024
@sholderbach
Copy link
Member

This is basically #9698 rearing its head by returning nothing.

@sholderbach
Copy link
Member

Closing in favor of #12956 as we collected more cases there.

@sholderbach sholderbach closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inconsistent-behavior Behavior between different commands or types inconsistent/unexpected syntax Changes to the grammar or syntax beyond parser bugfixes
Projects
None yet
Development

No branches or pull requests

3 participants