{-# LANGUAGE LambdaCase #-}

{-# OPTIONS_GHC -Wno-orphans #-}   -- instance Outputable GhcHint

module GHC.Types.Hint.Ppr (
  perhapsAsPat
  -- also, and more interesting: instance Outputable GhcHint
  ) where

import GHC.Prelude

import GHC.Parser.Errors.Basic
import GHC.Types.Hint

import GHC.Hs.Expr ()   -- instance Outputable
import {-# SOURCE #-} GHC.Tc.Types.Origin ( ClsInstOrQC(..) )
import GHC.Types.Id
import GHC.Types.Name (NameSpace, pprDefinedAt, occNameSpace, pprNameSpace, isValNameSpace, nameModule)
import GHC.Types.Name.Reader (RdrName,ImpDeclSpec (..), rdrNameOcc, rdrNameSpace)
import GHC.Types.SrcLoc (SrcSpan(..), srcSpanStartLine)
import GHC.Unit.Module.Imported (ImportedModsVal(..))
import GHC.Unit.Types
import GHC.Utils.Outputable

import Data.List (intersperse)
import qualified Data.List.NonEmpty as NE

instance Outputable GhcHint where
  ppr :: GhcHint -> SDoc
ppr = \case
    UnknownHint a
m
      -> forall a. Outputable a => a -> SDoc
ppr a
m
    SuggestExtension LanguageExtensionHint
extHint
      -> case LanguageExtensionHint
extHint of
          SuggestSingleExtension SDoc
extraUserInfo Extension
ext ->
            (forall doc. IsLine doc => String -> doc
text String
"Perhaps you intended to use" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Extension
ext) forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestAnyExtension SDoc
extraUserInfo [Extension]
exts ->
            let header :: SDoc
header = forall doc. IsLine doc => String -> doc
text String
"Enable any of the following extensions:"
            in  SDoc
header forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
hcat (forall a. a -> [a] -> [a]
intersperse (forall doc. IsLine doc => String -> doc
text String
", ") (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [Extension]
exts)) forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestExtensions SDoc
extraUserInfo [Extension]
exts ->
            let header :: SDoc
header = forall doc. IsLine doc => String -> doc
text String
"Enable all of the following extensions:"
            in  SDoc
header forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
hcat (forall a. a -> [a] -> [a]
intersperse (forall doc. IsLine doc => String -> doc
text String
", ") (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [Extension]
exts)) forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestExtensionInOrderTo SDoc
extraUserInfo Extension
ext ->
            (forall doc. IsLine doc => String -> doc
text String
"Use" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Extension
ext) forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
    SuggestCorrectPragmaName [String]
suggestions
      -> forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant" forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
quotedListWithOr (forall a b. (a -> b) -> [a] -> [b]
map forall doc. IsLine doc => String -> doc
text [String]
suggestions)
    GhcHint
SuggestMissingDo
      -> forall doc. IsLine doc => String -> doc
text String
"Possibly caused by a missing 'do'?"
    GhcHint
SuggestLetInDo
      -> forall doc. IsLine doc => String -> doc
text String
"Perhaps you need a 'let' in a 'do' block?"
           forall doc. IsDoc doc => doc -> doc -> doc
$$ forall doc. IsLine doc => String -> doc
text String
"e.g. 'let x = 5' instead of 'x = 5'"
    SuggestAddSignatureCabalFile ModuleName
pi_mod_name
      -> forall doc. IsLine doc => String -> doc
text String
"Try adding" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name)
           forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"to the"
           forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
"signatures")
           forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"field in your Cabal file."
    SuggestSignatureInstantiations ModuleName
pi_mod_name [InstantiationSuggestion]
suggestions
      -> let suggested_instantiated_with :: SDoc
suggested_instantiated_with =
               forall doc. IsLine doc => [doc] -> doc
hcat (forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
comma forall a b. (a -> b) -> a -> b
$
                   [ forall a. Outputable a => a -> SDoc
ppr ModuleName
k forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => String -> doc
text String
"=" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr Module
v
                   | InstantiationSuggestion ModuleName
k Module
v <- [InstantiationSuggestion]
suggestions
                   ])
         in forall doc. IsLine doc => String -> doc
text String
"Try passing -instantiated-with=\"" forall doc. IsLine doc => doc -> doc -> doc
<>
              SDoc
suggested_instantiated_with forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => String -> doc
text String
"\"" forall doc. IsDoc doc => doc -> doc -> doc
$$
                forall doc. IsLine doc => String -> doc
text String
"replacing <" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => String -> doc
text String
"> as necessary."
    GhcHint
SuggestUseSpaces
      -> forall doc. IsLine doc => String -> doc
text String
"Please use spaces instead."
    SuggestUseWhitespaceAfter OperatorWhitespaceSymbol
sym
      -> forall doc. IsLine doc => String -> doc
text String
"Add whitespace after the"
           forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (OperatorWhitespaceSymbol -> SDoc
pprOperatorWhitespaceSymbol OperatorWhitespaceSymbol
sym) forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Char -> doc
char Char
'.'
    SuggestUseWhitespaceAround String
sym OperatorWhitespaceOccurrence
_occurrence
      -> forall doc. IsLine doc => String -> doc
text String
"Add whitespace around" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
sym) forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => Char -> doc
char Char
'.'
    GhcHint
SuggestParentheses
      -> forall doc. IsLine doc => String -> doc
text String
"Use parentheses."
    GhcHint
SuggestIncreaseMaxPmCheckModels
      -> forall doc. IsLine doc => String -> doc
text String
"Increase the limit or resolve the warnings to suppress this message."
    SuggestAddTypeSignatures AvailableBindings
bindings
      -> case AvailableBindings
bindings of
          -- This might happen when we have bindings which are /too complicated/,
          -- see for example 'DsCannotMixPolyAndUnliftedBindings' in 'GHC.HsToCore.Errors.Types'.
          -- In this case, we emit a generic message.
          AvailableBindings
UnnamedBinding   -> forall doc. IsLine doc => String -> doc
text String
"Add a type signature."
          NamedBindings (Name
x NE.:| [Name]
xs) ->
            let nameList :: SDoc
nameList = case [Name]
xs of
                  [] -> SDoc -> SDoc
quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr forall a b. (a -> b) -> a -> b
$ Name
x
                  [Name]
_  -> forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (SDoc -> SDoc
quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr) [Name]
xs forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"and" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
x)
            in forall doc. IsLine doc => [doc] -> doc
hsep [ forall doc. IsLine doc => String -> doc
text String
"Consider giving"
                    , SDoc
nameList
                    , forall doc. IsLine doc => String -> doc
text String
"a type signature"]
    SuggestBindToWildcard LHsExpr GhcTc
rhs
      -> SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"Suppress this warning by saying") Int
2 (SDoc -> SDoc
quotes forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => String -> doc
text String
"_ <-" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcTc
rhs)
    SuggestAddInlineOrNoInlinePragma Var
lhs_id Activation
rule_act
      -> forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"Add an INLINE[n] or NOINLINE[n] pragma for" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Var
lhs_id)
              , forall doc. IsOutput doc => doc -> doc
whenPprDebug (forall a. Outputable a => a -> SDoc
ppr (Var -> Activation
idInlineActivation Var
lhs_id) forall doc. IsDoc doc => doc -> doc -> doc
$$ forall a. Outputable a => a -> SDoc
ppr Activation
rule_act)
              ]
    SuggestAddPhaseToCompetingRule RuleName
bad_rule
      -> forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"Add phase [n] or [~n] to the competing rule"
              , forall doc. IsOutput doc => doc -> doc
whenPprDebug (forall a. Outputable a => a -> SDoc
ppr RuleName
bad_rule) ]
    GhcHint
SuggestIncreaseSimplifierIterations
      -> forall doc. IsLine doc => String -> doc
text String
"Set limit with -fconstraint-solver-iterations=n; n=0 for no limit"
    SuggestUseTypeFromDataKind Maybe RdrName
mb_rdr_name
      -> forall doc. IsLine doc => String -> doc
text String
"Use" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
"Type")
         forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"from" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
"Data.Kind") forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"instead."
         forall doc. IsDoc doc => doc -> doc -> doc
$$
           forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall doc. IsOutput doc => doc
empty
           (\RdrName
rdr_name ->
             forall doc. IsLine doc => String -> doc
text String
"NB: with NoStarIsType, " forall doc. IsLine doc => doc -> doc -> doc
<> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)
             forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"is treated as a regular type operator.")
           Maybe RdrName
mb_rdr_name

    GhcHint
SuggestQualifiedAfterModuleName
      -> forall doc. IsLine doc => String -> doc
text String
"Place" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
"qualified")
          forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"after the module name."
    GhcHint
SuggestThQuotationSyntax
      -> forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"Perhaps you intended to use quotation syntax of TemplateHaskell,"
              , forall doc. IsLine doc => String -> doc
text String
"but the type variable or constructor is missing"
              ]
    SuggestRoles [Role]
nearby
      -> case [Role]
nearby of
               []  -> forall doc. IsOutput doc => doc
empty
               [Role
r] -> forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Role
r)
               -- will this last case ever happen??
               [Role]
_   -> SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant one of these:")
                           Int
2 (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (SDoc -> SDoc
quotes forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Outputable a => a -> SDoc
ppr) [Role]
nearby)
    GhcHint
SuggestQualifyStarOperator
      -> forall doc. IsLine doc => String -> doc
text String
"To use (or export) this operator in"
            forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"modules with StarIsType,"
         forall doc. IsDoc doc => doc -> doc -> doc
$$ forall doc. IsLine doc => String -> doc
text String
"    including the definition module, you must qualify it."
    GhcHint
SuggestTypeSignatureForm
      -> forall doc. IsLine doc => String -> doc
text String
"A type signature should be of form <variables> :: <type>"
    SuggestAddToHSigExportList Name
_name Maybe Module
mb_mod
      -> let header :: SDoc
header = forall doc. IsLine doc => String -> doc
text String
"Try adding it to the export list of"
         in case Maybe Module
mb_mod of
              Maybe Module
Nothing -> SDoc
header forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"the hsig file."
              Just Module
mod -> SDoc
header forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr (forall unit. GenModule unit -> ModuleName
moduleName Module
mod) forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => String -> doc
text String
"'s hsig file."
    GhcHint
SuggestFixOrphanInstance
      -> forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"Move the instance declaration to the module of the class or of the type, or"
              , forall doc. IsLine doc => String -> doc
text String
"wrap the type with a newtype and declare the instance on the new type."
              ]
    GhcHint
SuggestAddStandaloneDerivation
      -> forall doc. IsLine doc => String -> doc
text String
"Use a standalone deriving declaration instead"
    GhcHint
SuggestFillInWildcardConstraint
      -> forall doc. IsLine doc => String -> doc
text String
"Fill in the wildcard constraint yourself"
    GhcHint
SuggestRenameForall
      -> forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"Consider using another name, such as"
              , SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
"forAll") forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
comma forall doc. IsLine doc => doc -> doc -> doc
<+>
                SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
"for_all") forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
comma forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"or" forall doc. IsLine doc => doc -> doc -> doc
<+>
                SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
"forall_") forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
dot ]
    SuggestAppropriateTHTick NameSpace
ns
      -> forall doc. IsLine doc => String -> doc
text String
"Perhaps use a" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
how_many forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"tick"
        where
          how_many :: SDoc
how_many
            | NameSpace -> Bool
isValNameSpace NameSpace
ns = forall doc. IsLine doc => String -> doc
text String
"single"
            | Bool
otherwise         = forall doc. IsLine doc => String -> doc
text String
"double"
    GhcHint
SuggestDumpSlices
      -> forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"If you bound a unique Template Haskell name (NameU)"
              , forall doc. IsLine doc => String -> doc
text String
"perhaps via newName,"
              , forall doc. IsLine doc => String -> doc
text String
"then -ddump-splices might be useful." ]
    SuggestAddTick (UntickedConstructor LexicalFixity
fixity Name
name)
      -> forall doc. IsLine doc => [doc] -> doc
hsep [ forall doc. IsLine doc => String -> doc
text String
"Use"
              , forall doc. IsLine doc => Char -> doc
char Char
'\'' forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
con
              , forall doc. IsLine doc => String -> doc
text String
"instead of"
              , SDoc
con forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
mb_dot ]
        where
          con :: SDoc
con = LexicalFixity -> Name -> SDoc
pprUntickedConstructor LexicalFixity
fixity Name
name
          mb_dot :: SDoc
mb_dot
            | LexicalFixity -> Name -> Bool
isBareSymbol LexicalFixity
fixity Name
name
            -- A final dot can be confusing for a symbol without parens, e.g.
            --
            --  * Use ': instead of :.
            = forall doc. IsOutput doc => doc
empty
            | Bool
otherwise
            = forall doc. IsLine doc => doc
dot

    SuggestAddTick UntickedPromotedThing
UntickedExplicitList
      -> forall doc. IsLine doc => String -> doc
text String
"Add a promotion tick, e.g." forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"'[x,y,z]" forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
dot
    SuggestMoveToDeclarationSite SDoc
what RdrName
rdr_name
      -> forall doc. IsLine doc => String -> doc
text String
"Move the" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
what forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"to the declaration site of"
         forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
dot
    SuggestSimilarNames RdrName
tried_rdr_name NonEmpty SimilarName
similar_names
      -> case NonEmpty SimilarName
similar_names of
            SimilarName
n NE.:| [] -> forall doc. IsLine doc => String -> doc
text String
"Perhaps use" forall doc. IsLine doc => doc -> doc -> doc
<+> SimilarName -> SDoc
pp_item SimilarName
n
            NonEmpty SimilarName
_          -> forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => String -> doc
text String
"Perhaps use one of these:"
                              , Int -> SDoc -> SDoc
nest Int
2 (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas SimilarName -> SDoc
pp_item forall a b. (a -> b) -> a -> b
$ forall a. NonEmpty a -> [a]
NE.toList NonEmpty SimilarName
similar_names) ]
        where
          tried_ns :: NameSpace
tried_ns = OccName -> NameSpace
occNameSpace forall a b. (a -> b) -> a -> b
$ RdrName -> OccName
rdrNameOcc RdrName
tried_rdr_name
          pp_item :: SimilarName -> SDoc
pp_item = NameSpace -> SimilarName -> SDoc
pprSimilarName NameSpace
tried_ns
    RemindFieldSelectorSuppressed RdrName
rdr_name [Name]
parents
      -> forall doc. IsLine doc => String -> doc
text String
"Notice that" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)
         forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"is a field selector" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
whose
         forall doc. IsDoc doc => doc -> doc -> doc
$$ forall doc. IsLine doc => String -> doc
text String
"that has been suppressed by NoFieldSelectors."
      where
        -- parents may be empty if this is a pattern synonym field without a selector
        whose :: SDoc
whose | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
parents = forall doc. IsOutput doc => doc
empty
              | Bool
otherwise    = forall doc. IsLine doc => String -> doc
text String
"belonging to the type" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. [a] -> SDoc
plural [Name]
parents
                                 forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => [a] -> SDoc
pprQuotedList [Name]
parents
    ImportSuggestion ImportSuggestion
import_suggestion
      -> ImportSuggestion -> SDoc
pprImportSuggestion ImportSuggestion
import_suggestion
    GhcHint
SuggestImportingDataCon
      -> forall doc. IsLine doc => String -> doc
text String
"Import the data constructor to bring it into scope"
    GhcHint
SuggestPlacePragmaInHeader
      -> forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant to place it in the module header?"
      forall doc. IsDoc doc => doc -> doc -> doc
$$ forall doc. IsLine doc => String -> doc
text String
"The module header is the section at the top of the file, before the" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall doc. IsLine doc => String -> doc
text String
"module") forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"keyword"
    GhcHint
SuggestPatternMatchingSyntax
      -> forall doc. IsLine doc => String -> doc
text String
"Use pattern-matching syntax instead"
    SuggestSpecialiseVisibilityHints Name
name
      -> forall doc. IsLine doc => String -> doc
text String
"Make sure" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Module
mod forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"is compiled with -O and that"
           forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"has an INLINABLE pragma"
         where
           mod :: Module
mod = HasDebugCallStack => Name -> Module
nameModule Name
name
    LoopySuperclassSolveHint PredType
pty ClsInstOrQC
cls_or_qc
      -> forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsLine doc => String -> doc
text String
"Add the constraint" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr PredType
pty) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"to the" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
what forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
comma
              , forall doc. IsLine doc => String -> doc
text String
"even though it seems logically implied by other constraints in the context." ]
        where
          what :: SDoc
          what :: SDoc
what = case ClsInstOrQC
cls_or_qc of
            ClsInstOrQC
IsClsInst -> forall doc. IsLine doc => String -> doc
text String
"instance context"
            IsQC {}   -> forall doc. IsLine doc => String -> doc
text String
"context of the quantified constraint"

perhapsAsPat :: SDoc
perhapsAsPat :: SDoc
perhapsAsPat = forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant an as-pattern, which must not be surrounded by whitespace"

-- | Pretty-print an 'ImportSuggestion'.
pprImportSuggestion :: ImportSuggestion -> SDoc
pprImportSuggestion :: ImportSuggestion -> SDoc
pprImportSuggestion (CouldImportFrom NonEmpty (Module, ImportedModsVal)
mods OccName
occ_name)
  | (Module
mod, ImportedModsVal
imv) NE.:| [] <- NonEmpty (Module, ImportedModsVal)
mods
  = forall doc. IsLine doc => [doc] -> doc
fsep
      [ forall doc. IsLine doc => String -> doc
text String
"Perhaps you want to add"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , forall doc. IsLine doc => String -> doc
text String
"to the import list"
      , forall doc. IsLine doc => String -> doc
text String
"in the import of"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod)
      , forall doc. IsLine doc => doc -> doc
parens (forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv)) forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
dot
      ]
  | Bool
otherwise
  = forall doc. IsLine doc => [doc] -> doc
fsep
      [ forall doc. IsLine doc => String -> doc
text String
"Perhaps you want to add"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , forall doc. IsLine doc => String -> doc
text String
"to one of these import lists:"
      ]
    forall doc. IsDoc doc => doc -> doc -> doc
$$
    Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsDoc doc => [doc] -> doc
vcat
        [ SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc -> doc
parens (forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv))
        | (Module
mod,ImportedModsVal
imv) <- forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Module, ImportedModsVal)
mods
        ])
pprImportSuggestion (CouldUnhideFrom NonEmpty (Module, ImportedModsVal)
mods OccName
occ_name)
  | (Module
mod, ImportedModsVal
imv) NE.:| [] <- NonEmpty (Module, ImportedModsVal)
mods
  = forall doc. IsLine doc => [doc] -> doc
fsep
      [ forall doc. IsLine doc => String -> doc
text String
"Perhaps you want to remove"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , forall doc. IsLine doc => String -> doc
text String
"from the explicit hiding list"
      , forall doc. IsLine doc => String -> doc
text String
"in the import of"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod)
      , forall doc. IsLine doc => doc -> doc
parens (forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv)) forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
dot
      ]
  | Bool
otherwise
  = forall doc. IsLine doc => [doc] -> doc
fsep
      [ forall doc. IsLine doc => String -> doc
text String
"Perhaps you want to remove"
      , SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , forall doc. IsLine doc => String -> doc
text String
"from the hiding clauses"
      , forall doc. IsLine doc => String -> doc
text String
"in one of these imports:"
      ]
    forall doc. IsDoc doc => doc -> doc -> doc
$$
    Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsDoc doc => [doc] -> doc
vcat
        [ SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc -> doc
parens (forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv))
        | (Module
mod,ImportedModsVal
imv) <- forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Module, ImportedModsVal)
mods
        ])

-- | Pretty-print a 'SimilarName'.
pprSimilarName :: NameSpace -> SimilarName -> SDoc
pprSimilarName :: NameSpace -> SimilarName -> SDoc
pprSimilarName NameSpace
_ (SimilarName Name
name)
  = SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Name
name) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc -> doc
parens (Name -> SDoc
pprDefinedAt Name
name)
pprSimilarName NameSpace
tried_ns (SimilarRdrName RdrName
rdr_name HowInScope
how_in_scope)
  = case HowInScope
how_in_scope of
      LocallyBoundAt SrcSpan
loc ->
        RdrName -> SDoc
pp_ns RdrName
rdr_name forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
loc'
          where
            loc' :: SDoc
loc' = case SrcSpan
loc of
              UnhelpfulSpan UnhelpfulSpanReason
l -> forall doc. IsLine doc => doc -> doc
parens (forall a. Outputable a => a -> SDoc
ppr UnhelpfulSpanReason
l)
              RealSrcSpan RealSrcSpan
l Maybe BufSpan
_ -> forall doc. IsLine doc => doc -> doc
parens (forall doc. IsLine doc => String -> doc
text String
"line" forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => Int -> doc
int (RealSrcSpan -> Int
srcSpanStartLine RealSrcSpan
l))
      ImportedBy ImpDeclSpec
is ->
        RdrName -> SDoc
pp_ns RdrName
rdr_name forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) forall doc. IsLine doc => doc -> doc -> doc
<+>
        forall doc. IsLine doc => doc -> doc
parens (forall doc. IsLine doc => String -> doc
text String
"imported from" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr (ImpDeclSpec -> ModuleName
is_mod ImpDeclSpec
is))

  where
    pp_ns :: RdrName -> SDoc
    pp_ns :: RdrName -> SDoc
pp_ns RdrName
rdr | NameSpace
ns forall a. Eq a => a -> a -> Bool
/= NameSpace
tried_ns = NameSpace -> SDoc
pprNameSpace NameSpace
ns
              | Bool
otherwise      = forall doc. IsOutput doc => doc
empty
      where ns :: NameSpace
ns = RdrName -> NameSpace
rdrNameSpace RdrName
rdr