Skip to content

prevent parser from parsing variables as units#12378

Merged
sholderbach merged 2 commits intonushell:mainfrom
merelymyself:patch-1
Apr 4, 2024
Merged

prevent parser from parsing variables as units#12378
sholderbach merged 2 commits intonushell:mainfrom
merelymyself:patch-1

Conversation

@merelymyself
Copy link
Copy Markdown
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
Copy Markdown
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.

Co-authored-by: Stefan Holderbach <sholderbach@users.noreply.github.com>
@sholderbach sholderbach added the notes:fixes Include the release notes summary in the "Bug fixes" section label Apr 4, 2024
@sholderbach sholderbach merged commit f0a073b into nushell:main Apr 4, 2024
@hustcer hustcer added this to the v0.93.0 milestone Apr 4, 2024
@crides
Copy link
Copy Markdown
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
Copy Markdown
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

notes:fixes Include the release notes summary in the "Bug fixes" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(range) parsing is weird

4 participants