Skip to content

Confusing type error for boolean values #16406

Closed

Description

@kaathewisegit

Describe the bug

When a boolean value is passed to a function which expects an int, "expected non-boolean value" is thrown instead of a more concrete "expected int".

How to reproduce

~> def test [--ports: list<int>] {}
~> test
~> test --ports [1 2 3]
~> test --ports [1 2 "true"]
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #26:1:19]
 1 │ test --ports [1 2 "true"]
   ·                   ───┬──
   ·                      ╰── expected int
   ╰────

~> test --ports [1 2 true]
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #27:1:19]
 1 │ test --ports [1 2 true]
   ·                   ──┬─
   ·                     ╰── expected non-boolean value
   ╰────

Expected behavior

"expected int" error in both cases.

Configuration

key value
version 0.106.1
major 0
minor 106
patch 1
branch
commit_hash 682d593
build_os linux-x86_64
build_target x86_64-unknown-linux-musl
rust_version rustc 1.86.0 (05f9846f8 2025-03-31)
rust_channel 1.86.0-x86_64-unknown-linux-musl
cargo_version cargo 1.86.0 (adf9b6ad1 2025-02-28)
build_time 2025-08-03 12:10:49 +03:00
build_rust_channel release
allocator standard
features default, plugin, rustls-tls, sqlite, trash-support
installed_plugins template 0.105.1
experimental_options example=false, reorder-cell-paths=false

Activity

  1. added
    status:needs-triage
    on Aug 11, 2025
  2. fdncred commented on Aug 11, 2025

    @fdncred
    Contributor

    For anyone looking to change this, it looks like the non-boolean error is coming from here:

    match bytes {
    b"true" => {
    if matches!(shape, SyntaxShape::Boolean) || matches!(shape, SyntaxShape::Any) {
    return Expression::new(working_set, Expr::Bool(true), span, Type::Bool);
    } else {
    working_set.error(ParseError::Expected("non-boolean value", span));
    return Expression::garbage(working_set, span);
    }
    }
    b"false" => {
    if matches!(shape, SyntaxShape::Boolean) || matches!(shape, SyntaxShape::Any) {
    return Expression::new(working_set, Expr::Bool(false), span, Type::Bool);
    } else {
    working_set.error(ParseError::Expected("non-boolean value", span));
    return Expression::garbage(working_set, span);
    }
    }
    b"null" => {
    return Expression::new(working_set, Expr::Nothing, span, Type::Nothing);
    }
    b"-inf" | b"inf" | b"NaN" => {
    return parse_float(working_set, span);
    }
    _ => {}
    }

  3. added a commit that references this issue on Aug 11, 2025
    751ef6e
  4. added this to the v0.107.0 milestone on Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions