Repository navigation
Description
Describe the bug
we've noticed, with @Eldyj and @fdncred over on the discord server a kinda strange behaviour when annotating an argument with the table type 😮
in the example below, i've tried to simplify the original lesscase function into what's causing the issue only
- the
: tablein the signature
original discussion: https://discord.com/channels/601130461678272522/615253963645911060/1060542132848431144
How to reproduce
define a foo command with
def foo [tab: table] {
$tab | describe
$tab
}run the following tests
1. expected to fail
> foo 10
Error: nu::parser::parse_mismatch (link)
× Parse mismatch during operation.
╭─[entry #9:1:1]
1 │ foo 10
· ─┬
· ╰── expected table
╰────> foo "foo"
Error: nu::parser::parse_mismatch (link)
× Parse mismatch during operation.
╭─[entry #10:1:1]
1 │ foo "foo"
· ──┬──
· ╰── expected table
╰────2. should fail because they violate the signature
> foo []
list<any>> foo [1, 2, 3]
list<int>
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
╰───┴───╯> foo [foo]
list<string>
╭───┬─────╮
│ 0 │ foo │
╰───┴─────╯> foo {a: "A", b: "B"}
record<a: string, b: string>
╭───┬───╮
│ a │ A │
│ b │ B │
╰───┴───╯3. should not fail because it respects the signature but still fails
> foo [[a b]; [1 2] [3, 4]]
Error: nu::parser::type_mismatch (link)
× Type mismatch.
╭─[entry #15:1:1]
1 │ foo [[a b]; [1 2] [3, 4]]
· ──────────┬──────────
· ╰── expected List(Any), found Table([])
╰────note that
> [[a b]; [1 2] [3, 4]] | describe
table<a: int, b: int>Expected behavior
i expected the following to work, and they did
> foo 10
> foo "foo"i kinda expected the following to fail
> foo []
> foo [1, 2, 3]
> foo [foo]
> foo {a: "A", b: "B"}
in the end, the four above are some particular views of table, imo everything apart from basic types such as int can be seen as a table, right?
i definitely expected the last one to work, because describe says it's a table
> foo [[a b]; [1 2] [3, 4]]Screenshots
No response
Configuration
| key | value |
|---|---|
| version | 0.73.1 |
| branch | main |
| commit_hash | a9bdc65 |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.66.0 (69f9c33d7 2022-12-12) (Arch Linux rust 1:1.66.0-1) |
| cargo_version | cargo 1.66.0 |
| pkg_version | 0.73.1 |
| build_time | 2023-01-06 19:10:15 +01:00 |
| build_rust_channel | debug |
| features | database, default, trash, which, zip |
| installed_plugins |
Additional context
No response
Activity
amtoine commentedon Jan 11, 2023
and there is definitely something going on with the signature parser 🤔
i was writing some functions to wrap the
goimplementation ofIPFS, calledkubo, but i get the followingbut this gives me
i have to remove the
: liston thechunkerargument to mitigate the error 👍also...
it's quite strange to get the following error when annotation with
: list<any>, isn't it? 😕convert SyntaxShape::Table into the corresponding Type (#7781)
convert SyntaxShape::Table into the corresponding Type (nushell#7781)
fdncred commentedon Feb 16, 2023
Hey @amtoine!
I think these are two separate issues.
The stuff in the first post is fixed for now. The only questionable thing is that records and tables work the same. The rest fail. Records and Tables work the same because a table is a list of Records.
The second issue is separate where you can't do
chunkers: list = [size-256144]as a parameter with a default. Can you please open that as a new issue? Then we can close this one.Also, I think the
list<any>thing is just saying that parameters of list type can't have defaults. I wonder if that's even in the source code. I'm betting we left it out. I'm really not sure what's going on there but that looks like a bug to me.amtoine commentedon Feb 18, 2023
hey there 👋 😋
yep i see that, thanks for the ping 😌
you're right, the last one that "does not behave as expected" is
foo {a: "A", b: "B"}but yeah, records and tables looks really the same!
however theses are not the same types 😕
should
{a: "A", b: "B"}and[[a b]; [1 2] [3, 4]]behave the same?okey, let me file another issue 😉
amtoine commentedon Feb 18, 2023
maybe we close this one?
even though the
record/table"equivalence" still looks a bit strange 😕'cause if
record ~ list<table>then the types really are different, right? 🤔fdncred commentedon Feb 18, 2023
I tend to think
<a record> | describeshould show a record and<a table> | describeshould show a table.amtoine commentedon Feb 18, 2023
agree 👌
but then what about a function that takes a
tableas above, should it give an error given arecord? 😏because a
tableis alist<record<_>>i would say it should give an error 🤔amtoine commentedon Feb 22, 2023
WindSoilder commentedon May 19, 2023
I think this issue is already resolved, I can't reproduce it on 0.80;
Will close it for now, fell free to re-open it if you still get the issue
amtoine commentedon May 19, 2023
good catch @WindSoilder, this looks solved 🥳