gluon-lang / gluon

A static, type inferred and embeddable language written in Rust.
https://gluon-lang.org
MIT License
3.21k stars 145 forks source link

Add syntax aware contexts to errors #145

Open Marwes opened 8 years ago

Marwes commented 8 years ago

We should have better, more human readable error messages. Elm has had a fair amount of praise for its error messages so stealing some ideas from it should be a good idea http://elm-lang.org/blog/compiler-errors-for-humans. From the blog post we can see that the error messages contain not only row and column information about where the error occurs but also that the error occurred in the 1st argument.

To do this we may add an enum as below in addition the the current Span which would meaning changing the signature of unify_span to take an AstLocation as well which each caller needs to supply with the extra information (which might need to be optional, at least to start with).

enum AstLocation {
    Argument { position: u32 },
    Array { position: u32 },
    Pattern { position : .. },
    IfElsePredicate,
    // ... more
}

This can be a bit bigger project but just adding a few AstLocation's may be good starting project.

Marwes commented 8 years ago

The above is just an idea, might be a good idea to look at how Elm represents it as well

brendanzab commented 8 years ago

This seems to be the root of the error reporting in the elm compiler: https://github.com/elm-lang/elm-compiler/tree/master/src/Reporting

Marwes commented 6 years ago

I did the the setup needed for this a while ago (see https://github.com/gluon-lang/gluon/blob/c450475fdca856580a6ec9a6854e0d5352eceb9e/check/src/typecheck.rs#L156-L158 ).

To continue on this just add another variant to enum Help which contains AstLocation. Then do as explained in https://github.com/gluon-lang/gluon/issues/145#issue-175042640