don't overrite arg's type if it's annotated explicitly#10424
Merged
sophiajt merged 3 commits intonushell:mainfrom Sep 20, 2023
Merged
don't overrite arg's type if it's annotated explicitly#10424sophiajt merged 3 commits intonushell:mainfrom
sophiajt merged 3 commits intonushell:mainfrom
Conversation
amtoine
reviewed
Sep 19, 2023
Member
amtoine
left a comment
There was a problem hiding this comment.
i really like these changes, small bug right but super confusing, thanks @WindSoilder 🙏
i propose to wait for after the release 😉
Closed
hardfau1t
pushed a commit
to hardfau1t/nushell
that referenced
this pull request
Dec 14, 2023
# Description Fixes: nushell#10410 So the following script is possible: ```nushell def a [b: any = null] { let b = ($b | default "default_b"); } a "given_b" ``` ## About the change When parsing signature, and nushell meets something like `a: any`, it force the parser to treat `a` as `any` type. This is what `arg_explicit_type` means, it's only set when we goes into `ParseMode::TypeMode`, and it will be reset to `false` if the token goes to next argument. so, when we have something like this: `def a [b: any = null] { $b }`, the type of `$b` won't be overwritten. But if we have something like this: `def a [b = null] { $b }`, the type of `$b` is not annotated, so we make it to be `nothing`(which is the type of null)
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.
Description
Fixes: #10410
So the following script is possible:
About the change
When parsing signature, and nushell meets something like
a: any, it force the parser to treataasanytype. This is whatarg_explicit_typemeans, it's only set when we goes intoParseMode::TypeMode, and it will be reset tofalseif the token goes to next argument.so, when we have something like this:
def a [b: any = null] { $b }, the type of$bwon't be overwritten.But if we have something like this:
def a [b = null] { $b }, the type of$bis not annotated, so we make it to benothing(which is the type of null)