Description
Now when we can test error/warning/hint messages (see tests/errors
), we should work on improving how they are printed, and if we need any more information stored in the Diagnostics
class, we can do that too.
Some bugs to fix:
Urgent improvements:
- When two error labels are on the same line, we have to draw an ascii-art from the underline (both on the same line) to the label (on two separate lines)
- When error labels point to different files, we draw both files, make sure everything works with multiple files
- Error labels in a single file should be merged, and lines sorted (currently a later line in a file can be printed first)
- Add tests for these errors that need improving into
tests/errors
- Add more tests into
tests/errors
for errors to sample a wide variety of error messages, right now we have 9, I am thinking at least 30 to 50. Test tokenizer, parser, semantics (I can't think of a codegen error that is either not temporary or a bug in semantics, so we don't need to test those) --- then once we change how errors are printed, we can see the impact (just run./run_tests.py -u
) to make sure all corner cases still look good:- Tokenizer errors (one or two)
- Parser errors (a few)
- Semantic errors (a lot)
Once these are fixed and tests added, we should work on good error messages, for example when you call a function f(1, 2)
and some of the arguments don't agree, to highlight the declaration (possibly in different file), show where it was imported in the current file, show the expected type, show the current type, and so on.
Other improvements:
- Optionally using unicode box drawing characters
- Example: Test error messages #412 (comment)
- This should probably be the default, including in our tests for errors, but a command line option
--no-unicode-errors
will replace unicode characters with just ascii characters.
- Optionally experiment with highlighting the text itself (in red or blue, possibly in the background) instead of using the
~~~
and----
underlines, this should save vertical space. This must be optional, as you need to be able to see colors. With--no-color
we should still print underlines. - We can also experiment with some nice html output, possibly printing the source code (syntax highlighted) and then highlighting errors/warnings/hints somehow, and when you hover over it with a mouse, show more information.
Why to improve error messages
Already the diagnostic messages in LPython/LFortran are very good, but we have the opportunity to push this to (almost) perfection, we have the infrastructure, we have the ideas (see above), so we should just do it. Every user will sooner or later see these messages, and if they are beautiful, clear, to the point, it's a pleasure to see, and you want to see more of them: it's an art, it is like a nice painting that the compiler presents to the user, on top of their code. It will be one reason to use our compilers, to get these messages, because it makes the process of developing the code a pleasure.