Repository navigation
Fix: missing parse error when extra tokens are given to let bindings - #12238
Merged
Merged
Conversation
yizhepku
marked this pull request as draft
March 19, 2024 14:54
yizhepku
marked this pull request as ready for review
March 19, 2024 15:05
Contributor
|
Thanks for looking into this! It would be great to have some tests that ensure your fix stays fixed. |
Contributor
Author
|
I've added a simple test case. |
WindSoilder
requested changes
Mar 20, 2024
WindSoilder
left a comment
Contributor
There was a problem hiding this comment.
Thank you for making some changes to improve nushell! I just leave some comment
Contributor
There was a problem hiding this comment.
Can you also add tests for const a int = 2, mut a string = "3"?
Contributor
Author
There was a problem hiding this comment.
Will do. But I suspect these tests will be obsolete if we refactor the parser code. I think my current fix is hacky.
Manual checks are added to `parse_let`, `parse_mut`, and `parse_const`.
WindSoilder
approved these changes
Mar 21, 2024
Contributor
|
Thanks! |
sholderbach
pushed a commit
that referenced
this pull request
Apr 16, 2024
# Description A little refactor that use `working_set.error` rather than `working_set.parse_errors.push`, which is reported here: #12238 > Inconsistent error reporting. Usage of both working_set.error() and working_set.parse_errors.push(). Using ParseError::Expected for an invalid variable name when there's ParseError::VariableNotValid (from parser.rs:5237). Checking variable names manually when there's is_variable() (from parser.rs:2905). # User-Facing Changes NaN # Tests + Formatting Done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Manual checks are added to
parse_let,parse_mut, andparse_const.parse_var_with_opt_typeis also fixed to updatespans_idxcorrectly. Fixes #12125.It's technically a fix, but I'd rather not merge this directly. I'm making this PR to bring into attention the code quality of the parser code. For example:
spans_idx. What is its purpose, and which parsing functions need it? I suspect it's possible to remove the usage ofspans_idxentirely.mutablemean forparse_var_with_opt_type()?working_set.error()andworking_set.parse_errors.push(). UsingParseError::Expectedfor an invalid variable name when there'sParseError::VariableNotValid(fromparser.rs:5237). Checking variable names manually when there'sis_variable()(fromparser.rs:2905).span()is a terrible name for a function that flattens a bunch of spans into one (fromnu-protocal/src/span.rs:92). The top-level comment (Used when you have a slice of spans of at least size 1) doesn't help either.I've only looked at a small portion of the parser code; I expect there are a lot more. These issues made it much harder to fix a simple bug like #12125. I believe we should invest some effort to cleanup the parser code, which will ease maintainance in the future. I'll willing to help if there is interest.