Skip to content

convert diagnostic messages prose in Ps messages into proper GhcHint(s)

Alfredo Di Napoli requested to merge wip/adinapoli-issue-20055 into master

See #20055 (closed) and #18516 for context.

This work-in-progress MR reaps the benefits of the refactoring work we have done as part of #18516 and starts moving the suggestions buried in parser messages' diagnostics where they belong, i.e. in the diagnosticHints implementation of the instance Diagnostic PsMessage.

This is a slightly invasive MR as it would change the current GHC output when it comes to certain diagnostic, but I think it's a necessary evil. In particular, historically GHC was never consistent in the way errors and warnings were emitted alongside suggestions. Check out the following excerpt:

    PsErrIllegalBangPattern e
      -> mkSimpleDecorated $ text "Illegal bang-pattern (use BangPatterns):" $$ ppr e
...
      -> mkSimpleDecorated $ text "Multi-way if-expressions need MultiWayIf turned on"
...
    PsErrIllegalQualifiedDo qdoDoc
      -> mkSimpleDecorated $ vcat
           [ text "Illegal qualified" <+> quotes qdoDoc <+> text "block"
           , text "Perhaps you intended to use QualifiedDo"
           ]
...

There are here at least 3 stylistic forms: one where the hint is short and quick between parentheses, one where is "hidden" in the diagnostic ("need MultiWayIf turned on") and one where is a bit more explicit and phrased like a suggestion "Perhaps you intended..". However, using the new diagnostic infrastructure, it means everything is printed consistently now, like this:

T16270.hs:26:12: error:
    Illegal bang-pattern
    !i
    Suggested fix: Perhaps you intended to use BangPatterns

T16270.hs:28:9: error:
    Illegal multi-way if-expression
    Suggested fix: Perhaps you intended to use MultiWayIf

qdofail002.hs:11:13:
    Illegal qualified ‘P.mdo’ block
    Suggested fix: Perhaps you intended to use QualifiedDo

My goal here is not to change the existing prose of the messages (although I am polishing it as I see fit), as that would be too much of an opinionated/bikesheddy task for me to do. Hopefully somebody else can step up for the task, and we can discuss this further as part of a larger ticket/proposal. 😉

Edited by Alfredo Di Napoli

Merge request reports