Skip to content

nushell functions see tables as non-table and non-tables as table #7699

@amtoine

Description

@amtoine

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 : table in 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:parserIssues related to parsingA:type-systemProblems or features related to nushell's type systemcategory:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions