Repository navigation
Also type-check optional arguments - #16194
Merged
Merged
Conversation
Not doing so looks like an oversight.
WindSoilder
approved these changes
Jul 17, 2025
WindSoilder
left a comment
Contributor
There was a problem hiding this comment.
Thank you! It looks good to me
WindSoilder
approved these changes
Jul 17, 2025
hardfau1t
pushed a commit
to hardfau1t/nushell
that referenced
this pull request
Aug 25, 2025
# Description
Type-check all closure arguments, not just required arguments.
Not doing so looks like an oversight.
# User-Facing Changes
Previously, passing an argument of the wrong type to a closure would
fail if the argument is required, but be accepted (ignoring the type
annotation) if the argument is optional:
```
> do {|x: string| $x} 4
Error: nu::shell::cant_convert
× Can't convert to string.
╭─[entry nushell#13:1:21]
1 │ do {|x: string| $x} 4
· ┬
· ╰── can't convert int to string
╰────
> do {|x?: string| $x} 4
4
> do {|x?: string| $x} 4 | describe
int
```
It now fails the same way in both cases.
# Tests + Formatting
Added tests, the existing tests still pass.
Please let me know if I added the wrong type of test or added them in
the wrong place (I didn't spot similar tests in the nu-cmd-lang crate,
so I put them next to the most-related existing tests I could find...
# After Submitting
I think this is minor enough it doesn't need a doc update, but please
point me in the right direction if not.
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
Type-check all closure arguments, not just required arguments.
Not doing so looks like an oversight.
User-Facing Changes
Previously, passing an argument of the wrong type to a closure would fail if the argument is required, but be accepted (ignoring the type annotation) if the argument is optional:
It now fails the same way in both cases.
Tests + Formatting
Added tests, the existing tests still pass.
Please let me know if I added the wrong type of test or added them in the wrong place (I didn't spot similar tests in the nu-cmd-lang crate, so I put them next to the most-related existing tests I could find...
After Submitting
I think this is minor enough it doesn't need a doc update, but please point me in the right direction if not.