Convert UnknownTcRnMessage diagnostics into proper type constructors
This issue capitalises on the refactoring work done in #19930 (closed). Now GHC has a multitude of TcRn errors and warnings constructed by using the TcRnUnknownMessage type constructor from GHC.Tc.Errors.Types, which simply wraps an SDoc.
This ticket is about grepping the codebase for all these diagnostics and convert as many of them into proper type constructors in TcRnMessage.
Practical example
We currently have in GHC.Rename.Pat.rnConPatAndThen:
check_lang_exts :: RnM ()
check_lang_exts = do
scoped_tyvars <- xoptM LangExt.ScopedTypeVariables
type_app <- xoptM LangExt.TypeApplications
unless (scoped_tyvars && type_app) $
case listToMaybe tyargs of
Nothing -> pure ()
Just tyarg -> addErr $ TcRnUnknownMessage $ mkPlainError noHints $
hang (text "Illegal visible type application in a pattern:"
<+> quotes (char '@' <> ppr tyarg))
2 (text "Both ScopedTypeVariables and TypeApplications are"
<+> text "required to use this feature")
This should be converted into a new type constructor for TcRnMessage like:
... | TcRnIllegalVisTyAppInPat (HsPatSigType (NoGhcTc GhcPs))
And later give this a proper implementation for the diagnosticMessage and diagnosticHints, so that we can refactor check_lang_exts to be:
check_lang_exts :: RnM ()
check_lang_exts = do
scoped_tyvars <- xoptM LangExt.ScopedTypeVariables
type_app <- xoptM LangExt.TypeApplications
unless (scoped_tyvars && type_app) $
case listToMaybe tyargs of
Nothing -> pure ()
Just tyarg -> addErr $ TcRnIllegalVisTyAppInPat tyarg
On the hint front, it looks like this might warrant a new type of hint (or a modification of SuggestExtension) that suggests a set of extensions rather than just one.