Skip to content

nushell 0.86 regression: command option type and value is incorrectly inferred from default value #11033

Closed

Description

@srackham

Describe the bug

In the following tests, explicitly typing an int option (--age) causes the next option (--name) to default to false instead of "foobar":

#[test]
def test-cmd1 [] {
    assert equal (cmd1) "foobar" # PASS
}

def cmd1 [
    --age = 0
    --name = "foobar"
] {
    $name   # "foobar"
}

#[test]
def test-cmd2 [] {
    assert equal (cmd2) "foobar" # FAIL
}

def cmd2 [
    --age: int = 0
    --name = "foobar"
] {
    $name   # false
}

#[test]
def test-cmd3 [] {
    assert equal (cmd3) "foobar" # FAIL
}

def cmd3 [
    --age: int
    --name = "foobar"
] {
    $name   # false
}

How to reproduce

Run the above tests.

Expected behavior

The above tests should pass.

Screenshots

No response

Configuration

key value
version 0.86.0
branch makepkg
commit_hash 5d8763e
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.73.0 (cc66ad468 2023-10-03) (Arch Linux rust 1:1.73.0-1)
cargo_version cargo 1.73.0
build_time 2023-10-18 08:45:09 +00:00
build_rust_channel release
allocator mimalloc
features dataframe, default, extra, sqlite, trash, which, zip
installed_plugins

Additional context

No response

Activity

  1. added
    status:needs-triage
    on Nov 12, 2023
  2. added
    category:bug
    on Nov 12, 2023
  3. fdncred commented on Nov 12, 2023

    @fdncred
    Contributor

    Seems like a odd bug.

  4. amtoine commented on Nov 12, 2023

    @amtoine
    Member

    no need to run tests or anything 😉

    def foo [
        --age: int = 0
        --name = "foobar"
    ] {
        print $"age: ($age)"
        print $"name: ($name)"
    }

    then

    > foo
    age: 0
    name: false
    

    Note
    happens as long as there is a : int type annotation

  5. added
    A:parser
    A:type-system
    category:regression
    and removed
    status:needs-triage
    on Nov 12, 2023
  6. srackham commented on Nov 12, 2023

    @srackham
    Author

    @amtoine Should read --age: int = 0 in above foo def.

  7. amtoine commented on Nov 12, 2023

    @amtoine
    Member

    @amtoine Should read --age: int = 0 in above foo def.

    wooopsie, wrong one 👀
    updated 😉 🙏

  8. self-assigned this
    on Nov 12, 2023
  9. WindSoilder commented on Nov 12, 2023

    @WindSoilder
    Contributor

    If we have one comma after --age: int = 0, it works fine again...

    def foo [
        --age: int = 0,     # one , here..
        --name = "foobar"
    ] {
        print $"age: ($age)"
        print $"name: ($name)"
    }
  10. added a commit that references this issue on Nov 14, 2023
    942ff7d
  11. added this to the v0.87.0 milestone on Nov 14, 2023
  12. added a commit that references this issue on Dec 14, 2023
    002289e
  13. added a commit that references this issue on Feb 20, 2024
    54f8508
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A:parserA:type-systemcategory:bugcategory:regression

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions