haskell / haskell/error-messages

Parse errors should include context

Open
#52 0 comments 0 reactions 0 assignees View on GitHub
status:Composing error message tool:GHC type:error-message
Dominant language
No language data
Stars
76
Forks
19
PR merge metrics
No merged PRs in 30d

Description

Currently, when a parse error occurs, the error message says `parse error`, **but includes no information whatsoever about what caused the parse error**. This should be unacceptable. For someone who doesn't know the exact syntax (and for everyone else too), this is a horrible error message, it says almost nothing other than "something is wrong". I know that there are already some issues regarding this (I've linked them below), but I want to create a meta-issue for them to highlight the general problem.

The parse errors should describe what exactly is expected (a certain keyword, an expression, ...). Some examples:
* incomplete `if` expression (e.g. `if`, `if True`, `if True then`, `if True then 42`, ...): suggest something like "expected an expression" (for `if`, `if True then`, ...) or "expected 'then'" (for `if True`)
* `module`, `module Lib`: suggest "expected a module name" (for `module`) or "expected 'where' or a list of exported items" (for `module Lib`)
* ```hs
f x = -- this happens **very** often, especially to beginners
| True = x
```
emit an error message suggesting to remove the first `=`
* ```hs
class A a where
instance A Int
```
say something like "unexpected instance delcaration"

Previous `parse error` issues / more examples:
* #18
* #19
* #31

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.