Enable multiple locations for type errors
Nadrieril opened this issue · 2 comments
RIght now, errors look like this:
--> 1:6
|
1 | [] : List Type␊
| ^--^
|
= Type error: Wrong type of function argument
--> 1:11
|
1 | [] : List Type␊
| ^--^
|
= This argument has type Kind
[unknown location] But the function expected an argument of type Type
This is reasonably pretty, and uses internally the pest
Error
type for pretty-printing.
However this is limited to highlighting only one location at a time. For errors like the example above, it would be better to be able to highlight several locations at a time. Ideally, we'd get:
--> 1:6
|
1 | [] : List Type␊
| ^^^^ ____
| | |
| | this argument has type `Kind`
| |
| this function expects an argument of type `Type`
|
= Type error: Wrong type of function argument
More realistically, something like:
--> 1:6
|
1 | [] : List Type␊
| ^^^^ this function expects an argument of type `Type`
|
1 | [] : List Type␊
| ^^^^ this argument has type `Kind`
|
= Type error: Wrong type of function argument
would be quite good.
Instructions
Type errors are pretty-printed here. The error itself contains quite a bit of information already, which we would like to use. The pretty-printing code itself is here. You can see it uses pest::error::Error
to do its pretty-printing.
For this issue, you would need to implement more advanced printing, for example a function that takes a Vec<(Span, String)>
and renders something like
--> 1:6
|
1 | [] : List Type␊
| ^^^^ this function expects an argument of type `Type`
|
1 | [] : List Type␊
| ^^^^ this argument has type `Kind`
|
= Type error: Wrong type of function argument
You won't be able to use the pest code for that, but you can definitely copy-paste what they do as a starting point.
The objective here is something readable, and in the style of rustc error messages. Feel free to come up with a different API for constructing the output, or tweak the output. Writing error messages for more error variants is out of scope of this issue.
Feel free to ping me for questions !
I just discovered https://docs.rs/annotate-snippets/0.6.1/annotate_snippets/ , which looks like a solid foundation for this, instead of reinventing the wheel