Hide syntactic error context by default
Issues #15326 (closed) and #21722 (closed) asked for a flag to turn off the syntactic error context; this was implemented in e1bbd368.
In these discussions, the question of the right default was raised. I’m opening this new issue to continue that discussion.
Artem said
I wish the default value was reconsidered. The contexts are most harmful (in that they’re overwhelming) for newcomers, who will likely have no idea about the flag. On the other hand, if an expert wants to study a context, they can figure out that it’s hidden behind the flag.
Richard commented on both issues, with different points of view:
I'm happy with the default here. My reasoning is that defaults within GHC should be tuned for the simplest possible environment: running
ghc
in a terminal with no fancy editor around. In this scenario, the contexts may indeed be helpful. On the other hand, an IDE may be configured to pass lots and lots of different flags to GHC to get just the right output, and so an IDE is in a great position to suppress the context messages when appropriate.It's true that newcomers may stumble over the long error messages, but I hope we're directing newcomers to use IDEs, which make the learning experience smoother.
but also
And I agree that disabling them by default is fine.
Indeed, I wish to ask for something more drastic: what if we just dropped them entirely? Actually, I take that back: they are useful in places where the error is not in the user-written source code (like in
deriving
and Template Haskell-spliced code). Of course, if we hadSrcProv
(the enhancement toSrcSpan
originally proposed in #17582, but since abandoned, over my wails of disagreement), then we could just remove these contexts entirely, as we'd be able to print something sensible in the non-user-written source code case.
I also wrote:
I came here to open an issue asking for the error context to be hidden by default, now that we have the source span included in the error message, visualized as a quote of the actual code:
Error.hs:4:1: error: [GHC-48361] • Binding type variables is not allowed in pattern bindings • In the pattern: Just @a x In a pattern binding: Just @a x = Just (5 :: Integer) | 4 | Just @a x = Just (5 :: Integer) | ^^^^^^^^^
In this case, I find the error context does not add anything that I can’t tell faster from the source span.
But especially as someone who still is using
ghc
in the default scenario that Richard mentions (running it in a terminal with no fancy IDE around it), vertical screen space is very valuable – if I can see more error messages without scrolling, that’s better.Additionally, I believe that beginners, too, will benefit from a less cluttered presentation. (I’m writing this at MuniHac and just saw the beginners’s tutorial in the other room have a scarily long error message on the screen. Helping the reader to focus on what’s important would help).
So now that we have the exact-printed underlines code in error message, I’d advocate to change the default here.
Note that
It seems that ghci errors don't do the caret context thing? So there we might want to keep the syntactic context, or enable the caret context (for consistency)