Skip to content

Cant append list<type> in list<any> using ++= operator #8153

@glcraft

Description

@glcraft

Describe the bug

I created a mutable list which contains strings and paths at initialisation.
I want to append more items in the list using the ++= operator but the script won't compile, nu telling me it cant append list in list.

How to reproduce

Compile this :

mut args = [ 
    hello                        # string type
    ("hello" | path join world)  # path type
]
# => args is list<any>

$args ++= [ foo bar ]            # only strings

Nushell raise an error :

Error: nu::parser::type_mismatch (link)

  × Type mismatch during operation.
    ╭─[C:\Users\glitc\Projects\scripts-util\test.nu:8:1]
  8 │     ]
  9 │     $args ++= [ foo bar ]
    ·               ─────┬─────
    ·                    ╰── expected list<any>, found list<string>
 10 │     $args
    ╰────

Expected behavior

Being able to append list of any fixed type (e.g. list<string>, list<int>, list<path>, ...) in a list<any>

Screenshots

No response

Configuration

key value
version 0.75.0
branch
commit_hash 17a265b
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.66.1 (90743e729 2023-01-10)
rust_channel 1.66.1-x86_64-pc-windows-msvc
cargo_version cargo 1.66.1 (ad779e08b 2023-01-10)
pkg_version 0.75.0
build_time 2023-02-01 08:01:00 -06:00
build_rust_channel release
features database, default, trash, which, zip
installed_plugins

Additional context

In my example above, replacing $args ++= [ foo bar ] by $args = $args ++ [ foo bar ] works well

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:type-systemProblems or features related to nushell's type systemcategory:bugSomething isn't workingcategory:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpected

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions