Skip to content

Incorrect span in type_mismatch error message #7288

@epbuennig

Description

@epbuennig

Describe the bug

When declaring an int variable $val and trying to use binary addition on it with a string it would highlight the type mismatch before you evaluated the expression:

let val = 10
let var = "10"
$val + $var

I tried to see how far this on the fly analysis goes by turning a value into a string during evaluation.

let val = 10
($val | into string) + $var

In hindsight, obvious that this wouldn't be picked up without any special handling for into. Attempting to evaluate the expression anyway yields the following error message:

Error: nu::shell::type_mismatch (link)

  × Type mismatch during operation.
   ╭─[entry #11:1:1]
 1 │ ($val | into string) + $val
   ·  ──┬─                ┬ ──┬─
   ·    │                 │   ╰── int
   ·    │                 ╰── type mismatch for operator
   ·    ╰── string
   ╰────

Here, val is underlined as both a string in the left term and as a int in the right term, which is wrong since the whole left term evaluated to a string, not $val itself.

How to reproduce

  1. nu
  2. let val = 10
  3. ($val | into string) + $val

Expected behavior

An error message underlining the whole left term of the addition expression sort of like this:

Error: nu::shell::type_mismatch (link)

  × Type mismatch during operation.
   ╭─[entry #11:1:1]
 1 │ ($val | into string) + $val
   · ───┬──────────────── ┬ ──┬─
   ·    │                 │   ╰── int
   ·    │                 ╰── type mismatch for operator
   ·    ╰── string
   ╰────

Screenshots

No response

Configuration

key value
version 0.71.0
branch makepkg
commit_hash 6cc4ef6
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.65.0 (Arch Linux rust 1:1.65.0-1)
cargo_version cargo 1.65.0
pkg_version 0.71.0
build_time 2022-11-09 06:34:03 +00:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Additional context

Note the inconsistent highlighting between string + int and int + string, see #7289.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-unhelpfulThe error message you observe is not helpful to identify the problemgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions