Skip to content

fix panic when ..= syntax is used in stepped ranges#16231

Merged
sholderbach merged 3 commits intonushell:mainfrom
sgvictorino:fix-range-panic
Jul 30, 2025
Merged

fix panic when ..= syntax is used in stepped ranges#16231
sholderbach merged 3 commits intonushell:mainfrom
sgvictorino:fix-range-panic

Conversation

@sgvictorino
Copy link
Copy Markdown
Contributor

@sgvictorino sgvictorino commented Jul 23, 2025

Fixes #16185

Description

Stepped range literals where ..= precedes the second value no longer
cause a parser panic:

random int 1..=3..5
-Error:   x Main thread panicked.
-  |-> at crates/nu-protocol/src/engine/state_working_set.rs:400:48
-  `-> slice index starts at 8 but ends at 7
+Error: nu::parser::parse_mismatch
+
+  × Parse mismatch during operation.
+   ╭─[entry #1:1:15]
+ 1 │ random int 1..=3..5
+   ·               ─┬
+   ·                ╰── expected number

Release notes summary

Stepped range literals where ..= precedes the second value no longer cause a parser panic. e.g: random int 1..=3..5

# Description

Stepped range literals where `..=` precedes the second value no longer
cause a parser panic:

```
> 1..=3.. == 1..3..
Error:   x Main thread panicked.
  |-> at crates/nu-protocol/src/engine/state_working_set.rs:400:48
  `-> slice index starts at 8 but ends at 7
```
@github-actions github-actions bot added the A:parser Issues related to parsing label Jul 23, 2025
@sholderbach
Copy link
Copy Markdown
Member

Thanks for looking into this.

I am personally not sure if we should support the equal sign ahead of the next position as well.

I think a..b..=c feels ok but a..=b..c/a..=b..=c is stretching the existing redundancy in the syntax. We don't differentiate the handling of the next position if i recall with a a..<b..c / a..<b..<c

@sgvictorino sgvictorino changed the title allow ..= syntax in stepped ranges fix panic when ..= syntax is used in stepped ranges Jul 29, 2025
@sgvictorino sgvictorino closed this by deleting the head repository Jul 29, 2025
@sgvictorino sgvictorino reopened this Jul 29, 2025
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 figuring this out!

The range parsing really breaks my mental model for parsing. Thanks for the tests!

I have thrown the fuzzer against your branch and so far haven't been able to unearth another range rambunctiousness :)

@sholderbach sholderbach added the notes:fixes Include the release notes summary in the "Bug fixes" section label Jul 30, 2025
@sholderbach sholderbach merged commit 89c0e32 into nushell:main Jul 30, 2025
18 of 32 checks passed
@github-actions github-actions bot added this to the v0.107.0 milestone Jul 30, 2025
@sgvictorino sgvictorino deleted the fix-range-panic branch August 28, 2025 04:18
@132ikl 132ikl added the notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes. label Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing notes:fixes Include the release notes summary in the "Bug fixes" section notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic while parsing range

3 participants