nushell
nushell copied to clipboard
unexpected type mismatch: expected String, found Record([])
Describe the bug
def provideStr [r: record] {
"test"
}
def needStr [str: string] {
echo $str
}
def run [r: record] {
needStr (provideStr $r)
}
run {a:b}
This script errors with:
Error: nu::parser::type_mismatch (link)
× Type mismatch.
╭─[/d/dev/nu/test.nu:9:1]
9 │ def run [r: record] {
10 │ needStr (provideStr $r)
· ───────┬───────
· ╰── expected String, found Record([])
11 │ }
╰────
But provideStr does return a string. Putting the expression around quotes ((provideStr $r) -> $"(provideStr $r)") solves this issue but it looks unnecessary.
The more curious case is, that r has to be a parameter and not a variable. This script runs just fine:
def provideStr [r: record] {
"test"
}
def needStr [str: string] {
echo $str
}
let r = {a:b}
needStr (provideStr $r)
How to reproduce
- create a file named
test.nuwith the content:
def provideStr [r: record] {
"test"
}
def needStr [str: string] {
echo $str
}
def run [r: record] {
needStr (provideStr $r)
}
run {a:b}
- run it with
nu test.nu
Expected behavior
I expect nu to use the output from provideStr as positional parameter for the needStr command.
Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.75.0 |
| branch | |
| commit_hash | |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.68.0-nightly (0442fbabe 2023-01-10) |
| rust_channel | nightly-x86_64-unknown-linux-gnu |
| cargo_version | cargo 1.68.0-nightly (8c460b223 2023-01-04) |
| pkg_version | 0.75.0 |
| build_time | 2023-02-08 17:29:13 +01:00 |
| build_rust_channel | release |
| features | database, dataframe, default, trash, which, zip |
| installed_plugins |
Additional context
No response