enable flag value type checking (#11311)

# Description
Fixes: #11310

# User-Facing Changes
After the change, the following code will go to error:
```nushell
> def a [--x: int = 3] { "aa" }
> let y = "aa"
> a --x=$y
Error: nu::parser::type_mismatch

  × Type mismatch.
   ╭─[entry #32:2:1]
 2 │ let y = "aa"
 3 │ a --x=$y
   ·       ─┬
   ·        ╰── expected int, found string
   ╰────
```
This commit is contained in:
WindSoilder
2023-12-20 18:07:19 +08:00
committed by GitHub
parent 1cecb37628
commit 697f3c03f1
2 changed files with 59 additions and 23 deletions

View File

@ -73,6 +73,14 @@ fn custom_switch1() -> TestResult {
)
}
#[test]
fn custom_flag_with_type_checking() -> TestResult {
fail_test(
r#"def florb [--dry-run: int] { $dry_run }; let y = "3"; florb --dry-run=$y"#,
"type_mismatch",
)
}
#[test]
fn custom_switch2() -> TestResult {
run_test(
@ -116,7 +124,7 @@ fn custom_flag1() -> TestResult {
r#"def florb [
--age: int = 0
--name = "foobar"
] {
] {
($age | into string) + $name
}
florb"#,