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

prevent parser from parsing variables as units #12378

Merged
merged 2 commits into from Apr 4, 2024

Conversation

merelymyself
Copy link
Contributor

Description

Resolves #11274.

~/CodingProjects/nushell> let day = 2; echo 0..<$day
╭───┬───╮
│ 0 │ 0 │
│ 1 │ 1 │
╰───┴───╯
~/CodingProjects/nushell> let kb = "jan"; echo 0..$kb 
Error: nu::shell::type_mismatch

  × Type mismatch during operation.
   ╭─[entry #1:1:22]
 1 │ let kb = "jan"; echo 0..$kb
   ·                      ┬─┬─┬─
   ·                      │ │ ╰── string
   ·                      │ ╰── type mismatch for operator
   ·                      ╰── int
   ╰────

User-Facing Changes

Tests + Formatting

Relevant test added 🆙

After Submitting

Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and test! You are really chipping away at our bug backlog.

crates/nu-parser/src/parser.rs Show resolved Hide resolved
Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
@sholderbach sholderbach added the pr:bugfix This PR fixes some bug label Apr 4, 2024
@sholderbach sholderbach merged commit f0a073b into nushell:main Apr 4, 2024
15 checks passed
@hustcer hustcer added this to the v0.93.0 milestone Apr 4, 2024
@crides
Copy link
Contributor

crides commented Apr 5, 2024

This doesn't fully resolve #11274.

Things like 0..$d is fine, but things like 0..$ab (where what-could-be-the-unit starts some chars after the $). It's easy to see why from the diff though... the lhs of the unit should really just be one of:

  1. number literals (ints, floats)
  2. variables ($ followed by identifier/cell path)
  3. parenthesized expressions (and let the evaluator deal with the incorrect type)

@sholderbach
Copy link
Member

Good point that we can rule out more for the lhs in parse_unit_value but that should be limited to just a numeric literal based on what our unit-literals support.

I am going to reopen #11274, it seems we have more to figure out around how the range expression parsing works or how the different literal/expression parses interact in their precedence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:bugfix This PR fixes some bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(range) parsing is weird
4 participants