Skip to content

WIP: Implement -f[no-]diagnostics-show-contexts

dramforever requested to merge dramforever/ghc:show-contexts into master

Motivation

Allows suppressing of (non-landmark) contexts in error messages.

See #15326 (closed) for motivation and discussion. Once the discussion settles this MR can be marked non-WIP.

The following is copied from the feature request:

A typical error looks like this:

bug.hs:17:7: warning: [-Wdeferred-type-errors]
    ? No instance for (PolyList t0 [Integer])
        arising from a use of ‘polyList’
    ? In the expression: polyList 1 2 3 4 5
      In an equation for ‘plh’: plh = polyList 1 2 3 4 5
   |
17 | plh = polyList 1 2 3 4 5
   |       ^^^^^^^^^^^^^^^^^^

Note the two lines starting with In. They waste two lines of error message space and now provides near zero utility since:

  1. There's a caret view right below that context.
  2. There are editor integrations that show squiggles right in the editor.

Now we have an option -f[no-]diagnostics-show-caret that disables the caret. It would be great to have one that disables those code context lines too.

This would make code errors shorter and easier to scroll through and read. And in editor integration, this would make the, say, error message popup less of a 'wall of text'.

Considerations

I picked the cautious route of keeping the contexts by default, because I noticed that a large number of tests could be affected since removing contexts changes lots of diagnostics.

Update: I disabled the contexts by default, but made the tests show them as before so that I did not have to change a lot of expected outputs. Is this fine? Did I change the flags the right way?

The current name -f[no-]diagnostics-show-contexts is picked to be similar to -f[no-]diagnostics-show-caret but the word 'context' could be confused with type-class contexts.

An alternative is -fshow-expression-contexts proposed by @rae

Edited by dramforever

Merge request reports