-
Notifications
You must be signed in to change notification settings - Fork 326
Add Dotty error messages post #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
heathermiller
merged 1 commit into
scala:master
from
felixmulder:topic/post-dotty-errors
Oct 14, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
layout: blog | ||
post-type: blog | ||
by: Felix Mulder | ||
title: "Awesome Error Messages for Dotty" | ||
--- | ||
|
||
One thing that really excites me about being part of the core group of | ||
developers working on [Dotty](http://lampepfl.github.io/dotty) is my chance to | ||
impact usability. A lot of thought has gone into designing Dotty to be as fast | ||
and structurally sound as possible. Now comes the next step - adding a new | ||
level of usability for the compiler and the surrounding tools. | ||
|
||
We've looked at how other modern languages like | ||
[Elm](http://elm-lang.org/blog/compiler-errors-for-humans) and | ||
[Rust](https://blog.rust-lang.org/2016/08/10/Shape-of-errors-to-come.html) | ||
handle compiler warnings and error messages, and come to realize that Dotty is | ||
actually in great shape to provide comprehensive and easy to understand error | ||
messages in the same spirit. | ||
|
||
Let's dive right into some examples, let's say you have this code: | ||
|
||
try { | ||
foo() | ||
} | ||
|
||
It doesn't really make sense to put this in a `try`-block for two reasons: | ||
|
||
1. It doesn't throw an exception | ||
2. It doesn't have a `catch` or `finally` clause | ||
|
||
So let's say we compile this file using scalac, we get something like: | ||
|
||
<pre> | ||
test.scala:2: warning: A try without a catch or finally is equivalent to putting its body in a block; no exceptions are handled. | ||
try { | ||
^ | ||
one warning found | ||
</pre> | ||
|
||
This is helpful, but it has a couple of drawbacks: | ||
|
||
1. If we have a bazillion errors, it will be hard to read | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that really relevant, here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - the new errors have division between errors so you can see where one ends and another begins. |
||
2. If we don't know about `catch` or `finally` blocks - we don't know how to | ||
solve this (yes I know, most people do know what these are but - toy | ||
example!) | ||
|
||
So what do you get with Dotty? This: | ||
|
||
 | ||
|
||
All errors are now visually separated, and the output is colorized so that you | ||
can find your mistakes quickly. | ||
|
||
Another one of our goals is to be able to properly explain things when asked. | ||
As such, if you pass the flag `-explain` when compiling the example above, | ||
you'll get a more verbose explanation: | ||
|
||
 | ||
|
||
Mistyping members | ||
----------------- | ||
Sometimes, especially when you're in a rush - you might mistype some members. | ||
Currently we offer you the following support when selecting on a type: | ||
|
||
class Foo { | ||
def bar = ??? | ||
} | ||
|
||
val foo = new Foo() | ||
foo.barr | ||
|
||
Will yield: | ||
|
||
 | ||
|
||
In the future we want to be able to offer you these types of suggestions on | ||
other things like missing imports. | ||
|
||
Type diffs | ||
---------- | ||
Sometimes when working with complex types - it's hard to see exactly where the | ||
error occurs. The Dotty compiler will in these cases give you a colored diff: | ||
|
||
 | ||
|
||
It will not do this however if the differences are huge - but it will syntax | ||
highlight the found and expected type anyway. | ||
|
||
We want you! | ||
------------ | ||
To make the transition to these new error messages as quick and pain-free as | ||
possible - we need help! This is a perfect entry-point into hacking on the | ||
compiler as you'll need to create semantic objects that contain the relevant | ||
information for the error or warning. | ||
|
||
So - this is what you do: | ||
|
||
1. Go to the [Error messages issue](https://github.com/lampepfl/dotty/issues/1589) | ||
2. Read the howto on error messages | ||
3. Choose an error message you want to help with and post a comment saying | ||
which one(s) | ||
4. Get hacking | ||
5. Submit a PR! |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is irrelevant to the present discussion. I suggest you replace
1 + 2
byfoo()
, and let the reader figure out thatfoo()
might throw an exception.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright!