Skip to content

Include function name in error messages #239

@antocuni

Description

@antocuni

Consider the following:

def foo() -> int:
    return 1 + "hello"

def main() -> None:
    foo()

Currently, we get this error:

❯ spy /tmp/x.spy 
TypeError: cannot do `i32` + `str`
   --> /tmp/x.spy:2:12
  2 |     return 1 + "hello"
    |            ^ this is `i32`

   --> /tmp/x.spy:2:16
  2 |     return 1 + "hello"
    |                |_____| this is `str`

   --> /tmp/x.spy:2:12
  2 |     return 1 + "hello"
    |            |_________| operator::ADD called here
Image

I think it would be nice to include the function name (or even better, the FQN) in the error message. Something like this:

❯ spy /tmp/x.spy 
TypeError: cannot do `i32` + `str`
  In function `x::foo`:
   --> /tmp/x.spy:2:12
  2 |     return 1 + "hello"
    |            ^ this is `i32`

   --> /tmp/x.spy:2:16
  2 |     return 1 + "hello"
    |                |_____| this is `str`

   --> /tmp/x.spy:2:12
  2 |     return 1 + "hello"
    |            |_________| operator::ADD called here

I honestly don't know what is the best way to present/format it, I'm open to suggestion. I think it would be good to see what other "modern" compilers do in similar cases (e.g. rust, zig, go).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions