nushell/tests/shell
Wind 5596190377
do command: Make closure support default parameters and type checking (#12056)
# Description
Fixes: #11287
Fixes: #11318

It's implemented by porting the similar logic in `eval_call`, I've tried
to reduce duplicate code, but it seems that it's hard without using
macros.

3ee2fc60f9/crates/nu-engine/src/eval.rs (L60-L130)

It only works for `do` command.

# User-Facing Changes
## Closure supports optional parameter
```nushell
let code = {|x?| print ($x | default "i'm the default")}
do $code
```
Previously it raises an error, after this change, it prints `i'm the
default`.

## Closure supports type checking
```nushell
let code = {|x: int| echo $x}
do $code "aa"
```
After this change, it will raise an error with a message: `can't convert
string to int`

# Tests + Formatting
Done

# After Submitting
NaN
2024-03-11 18:11:08 +08:00
..
environment test: clear parent envs to prevent leakage to tests (#9976) 2023-08-14 12:49:55 +02:00
pipeline do command: Make closure support default parameters and type checking (#12056) 2024-03-11 18:11:08 +08:00
mod.rs Fix a panic when parsing empty file (#11314) 2024-02-07 18:47:44 -06:00