{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
{-# LANGUAGE ParallelListComp #-}
module GHC.Tc.Errors(
reportUnsolved, reportAllUnsolved, warnAllUnsolved,
warnDefaulting,
solverReportMsg_ExpectedActuals,
solverReportInfo_ExpectedActuals
) where
import GHC.Prelude
import GHC.Driver.Env (hsc_units)
import GHC.Driver.Session
import GHC.Driver.Ppr
import GHC.Driver.Config.Diagnostic
import GHC.Rename.Unbound
import GHC.Tc.Types
import GHC.Tc.Utils.Monad
import GHC.Tc.Errors.Types
import GHC.Tc.Errors.Ppr
import GHC.Tc.Types.Constraint
import GHC.Tc.Utils.TcMType
import GHC.Tc.Utils.Env( tcInitTidyEnv )
import GHC.Tc.Utils.TcType
import GHC.Tc.Utils.Unify ( checkTyVarEq )
import GHC.Tc.Types.Origin
import GHC.Tc.Types.Evidence
import GHC.Tc.Types.EvTerm
import GHC.Tc.Instance.Family
import GHC.Tc.Utils.Instantiate
import {-# SOURCE #-} GHC.Tc.Errors.Hole ( findValidHoleFits, getHoleFitDispConfig, pprHoleFit )
import GHC.Types.Name
import GHC.Types.Name.Reader ( lookupGRE_Name, GlobalRdrEnv, mkRdrUnqual
, emptyLocalRdrEnv, lookupGlobalRdrEnv , lookupLocalRdrOcc )
import GHC.Types.Id
import GHC.Types.Var
import GHC.Types.Var.Set
import GHC.Types.Var.Env
import GHC.Types.Name.Env
import GHC.Types.SrcLoc
import GHC.Types.Basic
import GHC.Types.Error
import qualified GHC.Types.Unique.Map as UM
import GHC.Unit.Module
import qualified GHC.LanguageExtensions as LangExt
import GHC.Core.Predicate
import GHC.Core.Type
import GHC.Core.Coercion
import GHC.Core.TyCo.Ppr ( pprTyVars
)
import GHC.Core.InstEnv
import GHC.Core.TyCon
import GHC.Core.DataCon
import GHC.Utils.Error (diagReasonSeverity, pprLocMsgEnvelope )
import GHC.Utils.Misc
import GHC.Utils.Outputable as O
import GHC.Utils.Panic
import GHC.Utils.Panic.Plain
import GHC.Utils.FV ( fvVarList, unionFV )
import GHC.Data.Bag
import GHC.Data.List.SetOps ( equivClasses, nubOrdBy )
import GHC.Data.Maybe
import qualified GHC.Data.Strict as Strict
import Control.Monad ( unless, when, foldM, forM_ )
import Data.Foldable ( toList )
import Data.Function ( on )
import Data.List ( partition, sort, sortBy )
import Data.List.NonEmpty ( NonEmpty(..), (<|) )
import qualified Data.List.NonEmpty as NE ( map, reverse )
import Data.Ord ( comparing )
import qualified Data.Semigroup as S
reportUnsolved :: WantedConstraints -> TcM (Bag EvBind)
reportUnsolved :: WantedConstraints -> TcM (Bag EvBind)
reportUnsolved WantedConstraints
wanted
= do { EvBindsVar
binds_var <- TcM EvBindsVar
newTcEvBinds
; Bool
defer_errors <- GeneralFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_DeferTypeErrors
; let type_errors :: DiagnosticReason
type_errors | Bool -> Bool
not Bool
defer_errors = DiagnosticReason
ErrorWithoutFlag
| Bool
otherwise = WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnDeferredTypeErrors
; Bool
defer_holes <- GeneralFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_DeferTypedHoles
; let expr_holes :: DiagnosticReason
expr_holes | Bool -> Bool
not Bool
defer_holes = DiagnosticReason
ErrorWithoutFlag
| Bool
otherwise = WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnTypedHoles
; Bool
partial_sigs <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.PartialTypeSignatures
; let type_holes :: DiagnosticReason
type_holes | Bool -> Bool
not Bool
partial_sigs
= DiagnosticReason
ErrorWithoutFlag
| Bool
otherwise
= WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnPartialTypeSignatures
; Bool
defer_out_of_scope <- GeneralFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_DeferOutOfScopeVariables
; let out_of_scope_holes :: DiagnosticReason
out_of_scope_holes | Bool -> Bool
not Bool
defer_out_of_scope
= DiagnosticReason
ErrorWithoutFlag
| Bool
otherwise
= WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnDeferredOutOfScopeVariables
; DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> EvBindsVar
-> WantedConstraints
-> TcM ()
report_unsolved DiagnosticReason
type_errors DiagnosticReason
expr_holes
DiagnosticReason
type_holes DiagnosticReason
out_of_scope_holes
EvBindsVar
binds_var WantedConstraints
wanted
; EvBindMap
ev_binds <- EvBindsVar -> TcM EvBindMap
getTcEvBindsMap EvBindsVar
binds_var
; Bag EvBind -> TcM (Bag EvBind)
forall (m :: * -> *) a. Monad m => a -> m a
return (EvBindMap -> Bag EvBind
evBindMapBinds EvBindMap
ev_binds)}
reportAllUnsolved :: WantedConstraints -> TcM ()
reportAllUnsolved :: WantedConstraints -> TcM ()
reportAllUnsolved WantedConstraints
wanted
= do { EvBindsVar
ev_binds <- TcM EvBindsVar
newNoTcEvBinds
; Bool
partial_sigs <- Extension -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. Extension -> TcRnIf gbl lcl Bool
xoptM Extension
LangExt.PartialTypeSignatures
; let type_holes :: DiagnosticReason
type_holes | Bool -> Bool
not Bool
partial_sigs = DiagnosticReason
ErrorWithoutFlag
| Bool
otherwise = WarningFlag -> DiagnosticReason
WarningWithFlag WarningFlag
Opt_WarnPartialTypeSignatures
; DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> EvBindsVar
-> WantedConstraints
-> TcM ()
report_unsolved DiagnosticReason
ErrorWithoutFlag
DiagnosticReason
ErrorWithoutFlag DiagnosticReason
type_holes DiagnosticReason
ErrorWithoutFlag
EvBindsVar
ev_binds WantedConstraints
wanted }
warnAllUnsolved :: WantedConstraints -> TcM ()
warnAllUnsolved :: WantedConstraints -> TcM ()
warnAllUnsolved WantedConstraints
wanted
= do { EvBindsVar
ev_binds <- TcM EvBindsVar
newTcEvBinds
; DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> EvBindsVar
-> WantedConstraints
-> TcM ()
report_unsolved DiagnosticReason
WarningWithoutFlag
DiagnosticReason
WarningWithoutFlag
DiagnosticReason
WarningWithoutFlag
DiagnosticReason
WarningWithoutFlag
EvBindsVar
ev_binds WantedConstraints
wanted }
report_unsolved :: DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> EvBindsVar
-> WantedConstraints -> TcM ()
report_unsolved :: DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> EvBindsVar
-> WantedConstraints
-> TcM ()
report_unsolved DiagnosticReason
type_errors DiagnosticReason
expr_holes
DiagnosticReason
type_holes DiagnosticReason
out_of_scope_holes EvBindsVar
binds_var WantedConstraints
wanted
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wanted
= () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { String -> SDoc -> TcM ()
traceTc String
"reportUnsolved {" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
vcat [ String -> SDoc
text String
"type errors:" SDoc -> SDoc -> SDoc
<+> DiagnosticReason -> SDoc
forall a. Outputable a => a -> SDoc
ppr DiagnosticReason
type_errors
, String -> SDoc
text String
"expr holes:" SDoc -> SDoc -> SDoc
<+> DiagnosticReason -> SDoc
forall a. Outputable a => a -> SDoc
ppr DiagnosticReason
expr_holes
, String -> SDoc
text String
"type holes:" SDoc -> SDoc -> SDoc
<+> DiagnosticReason -> SDoc
forall a. Outputable a => a -> SDoc
ppr DiagnosticReason
type_holes
, String -> SDoc
text String
"scope holes:" SDoc -> SDoc -> SDoc
<+> DiagnosticReason -> SDoc
forall a. Outputable a => a -> SDoc
ppr DiagnosticReason
out_of_scope_holes ]
; String -> SDoc -> TcM ()
traceTc String
"reportUnsolved (before zonking and tidying)" (WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanted)
; WantedConstraints
wanted <- WantedConstraints -> TcM WantedConstraints
zonkWC WantedConstraints
wanted
; let tidy_env :: TidyEnv
tidy_env = TidyEnv -> [TyCoVar] -> TidyEnv
tidyFreeTyCoVars TidyEnv
emptyTidyEnv [TyCoVar]
free_tvs
free_tvs :: [TyCoVar]
free_tvs = (TyCoVar -> Bool) -> [TyCoVar] -> [TyCoVar]
forall a. (a -> Bool) -> [a] -> [a]
filterOut TyCoVar -> Bool
isCoVar ([TyCoVar] -> [TyCoVar]) -> [TyCoVar] -> [TyCoVar]
forall a b. (a -> b) -> a -> b
$
WantedConstraints -> [TyCoVar]
tyCoVarsOfWCList WantedConstraints
wanted
; String -> SDoc -> TcM ()
traceTc String
"reportUnsolved (after zonking):" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Free tyvars:" SDoc -> SDoc -> SDoc
<+> [TyCoVar] -> SDoc
pprTyVars [TyCoVar]
free_tvs
, String -> SDoc
text String
"Tidy env:" SDoc -> SDoc -> SDoc
<+> TidyEnv -> SDoc
forall a. Outputable a => a -> SDoc
ppr TidyEnv
tidy_env
, String -> SDoc
text String
"Wanted:" SDoc -> SDoc -> SDoc
<+> WantedConstraints -> SDoc
forall a. Outputable a => a -> SDoc
ppr WantedConstraints
wanted ]
; Bool
warn_redundant <- WarningFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. WarningFlag -> TcRnIf gbl lcl Bool
woptM WarningFlag
Opt_WarnRedundantConstraints
; Bool
exp_syns <- GeneralFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_PrintExpandedSynonyms
; let err_ctxt :: SolverReportErrCtxt
err_ctxt = CEC :: [Implication]
-> TidyEnv
-> EvBindsVar
-> DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> DiagnosticReason
-> Bool
-> Bool
-> Bool
-> SolverReportErrCtxt
CEC { cec_encl :: [Implication]
cec_encl = []
, cec_tidy :: TidyEnv
cec_tidy = TidyEnv
tidy_env
, cec_defer_type_errors :: DiagnosticReason
cec_defer_type_errors = DiagnosticReason
type_errors
, cec_expr_holes :: DiagnosticReason
cec_expr_holes = DiagnosticReason
expr_holes
, cec_type_holes :: DiagnosticReason
cec_type_holes = DiagnosticReason
type_holes
, cec_out_of_scope_holes :: DiagnosticReason
cec_out_of_scope_holes = DiagnosticReason
out_of_scope_holes
, cec_suppress :: Bool
cec_suppress = WantedConstraints -> Bool
insolubleWC WantedConstraints
wanted
, cec_warn_redundant :: Bool
cec_warn_redundant = Bool
warn_redundant
, cec_expand_syns :: Bool
cec_expand_syns = Bool
exp_syns
, cec_binds :: EvBindsVar
cec_binds = EvBindsVar
binds_var }
; TcLevel
tc_lvl <- TcM TcLevel
getTcLevel
; SolverReportErrCtxt -> TcLevel -> WantedConstraints -> TcM ()
reportWanteds SolverReportErrCtxt
err_ctxt TcLevel
tc_lvl WantedConstraints
wanted
; String -> SDoc -> TcM ()
traceTc String
"reportUnsolved }" SDoc
empty }
important :: SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important :: SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important SolverReportErrCtxt
ctxt TcSolverReportMsg
doc = SolverReport
forall a. Monoid a => a
mempty { sr_important_msgs :: [SolverReportWithCtxt]
sr_important_msgs = [SolverReportErrCtxt -> TcSolverReportMsg -> SolverReportWithCtxt
SolverReportWithCtxt SolverReportErrCtxt
ctxt TcSolverReportMsg
doc] }
mk_relevant_bindings :: RelevantBindings -> SolverReport
mk_relevant_bindings :: RelevantBindings -> SolverReport
mk_relevant_bindings RelevantBindings
binds = SolverReport
forall a. Monoid a => a
mempty { sr_supplementary :: [SolverReportSupplementary]
sr_supplementary = [RelevantBindings -> SolverReportSupplementary
SupplementaryBindings RelevantBindings
binds] }
mk_report_hints :: [GhcHint] -> SolverReport
mk_report_hints :: [GhcHint] -> SolverReport
mk_report_hints [GhcHint]
hints = SolverReport
forall a. Monoid a => a
mempty { sr_hints :: [GhcHint]
sr_hints = [GhcHint]
hints }
deferringAnyBindings :: SolverReportErrCtxt -> Bool
deferringAnyBindings :: SolverReportErrCtxt -> Bool
deferringAnyBindings (CEC { cec_defer_type_errors :: SolverReportErrCtxt -> DiagnosticReason
cec_defer_type_errors = DiagnosticReason
ErrorWithoutFlag
, cec_expr_holes :: SolverReportErrCtxt -> DiagnosticReason
cec_expr_holes = DiagnosticReason
ErrorWithoutFlag
, cec_out_of_scope_holes :: SolverReportErrCtxt -> DiagnosticReason
cec_out_of_scope_holes = DiagnosticReason
ErrorWithoutFlag }) = Bool
False
deferringAnyBindings SolverReportErrCtxt
_ = Bool
True
maybeSwitchOffDefer :: EvBindsVar -> SolverReportErrCtxt -> SolverReportErrCtxt
maybeSwitchOffDefer :: EvBindsVar -> SolverReportErrCtxt -> SolverReportErrCtxt
maybeSwitchOffDefer EvBindsVar
evb SolverReportErrCtxt
ctxt
| CoEvBindsVar{} <- EvBindsVar
evb
= SolverReportErrCtxt
ctxt { cec_defer_type_errors :: DiagnosticReason
cec_defer_type_errors = DiagnosticReason
ErrorWithoutFlag
, cec_expr_holes :: DiagnosticReason
cec_expr_holes = DiagnosticReason
ErrorWithoutFlag
, cec_out_of_scope_holes :: DiagnosticReason
cec_out_of_scope_holes = DiagnosticReason
ErrorWithoutFlag }
| Bool
otherwise
= SolverReportErrCtxt
ctxt
reportImplic :: SolverReportErrCtxt -> Implication -> TcM ()
reportImplic :: SolverReportErrCtxt -> Implication -> TcM ()
reportImplic SolverReportErrCtxt
ctxt implic :: Implication
implic@(Implic { ic_skols :: Implication -> [TyCoVar]
ic_skols = [TyCoVar]
tvs
, ic_given :: Implication -> [TyCoVar]
ic_given = [TyCoVar]
given
, ic_wanted :: Implication -> WantedConstraints
ic_wanted = WantedConstraints
wanted, ic_binds :: Implication -> EvBindsVar
ic_binds = EvBindsVar
evb
, ic_status :: Implication -> ImplicStatus
ic_status = ImplicStatus
status, ic_info :: Implication -> SkolemInfoAnon
ic_info = SkolemInfoAnon
info
, ic_env :: Implication -> TcLclEnv
ic_env = TcLclEnv
tcl_env
, ic_tclvl :: Implication -> TcLevel
ic_tclvl = TcLevel
tc_lvl })
| SkolemInfoAnon
BracketSkol <- SkolemInfoAnon
info
, Bool -> Bool
not Bool
insoluble
= () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { String -> SDoc -> TcM ()
traceTc String
"reportImplic" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
vcat
[ String -> SDoc
text String
"tidy env:" SDoc -> SDoc -> SDoc
<+> TidyEnv -> SDoc
forall a. Outputable a => a -> SDoc
ppr (SolverReportErrCtxt -> TidyEnv
cec_tidy SolverReportErrCtxt
ctxt)
, String -> SDoc
text String
"skols: " SDoc -> SDoc -> SDoc
<+> [TyCoVar] -> SDoc
pprTyVars [TyCoVar]
tvs
, String -> SDoc
text String
"tidy skols:" SDoc -> SDoc -> SDoc
<+> [TyCoVar] -> SDoc
pprTyVars [TyCoVar]
tvs' ]
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
bad_telescope (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$ SolverReportErrCtxt
-> TcLclEnv -> SkolemInfoAnon -> [TyCoVar] -> TcM ()
reportBadTelescope SolverReportErrCtxt
ctxt TcLclEnv
tcl_env SkolemInfoAnon
info [TyCoVar]
tvs
; SolverReportErrCtxt -> TcLevel -> WantedConstraints -> TcM ()
reportWanteds SolverReportErrCtxt
ctxt' TcLevel
tc_lvl WantedConstraints
wanted
; Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (SolverReportErrCtxt -> Bool
cec_warn_redundant SolverReportErrCtxt
ctxt) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
SolverReportErrCtxt
-> TcLclEnv -> SkolemInfoAnon -> [TyCoVar] -> TcM ()
warnRedundantConstraints SolverReportErrCtxt
ctxt' TcLclEnv
tcl_env SkolemInfoAnon
info' [TyCoVar]
dead_givens }
where
insoluble :: Bool
insoluble = ImplicStatus -> Bool
isInsolubleStatus ImplicStatus
status
(TidyEnv
env1, [TyCoVar]
tvs') = TidyEnv -> [TyCoVar] -> (TidyEnv, [TyCoVar])
tidyVarBndrs (SolverReportErrCtxt -> TidyEnv
cec_tidy SolverReportErrCtxt
ctxt) ([TyCoVar] -> (TidyEnv, [TyCoVar]))
-> [TyCoVar] -> (TidyEnv, [TyCoVar])
forall a b. (a -> b) -> a -> b
$
[TyCoVar] -> [TyCoVar]
scopedSort [TyCoVar]
tvs
info' :: SkolemInfoAnon
info' = TidyEnv -> SkolemInfoAnon -> SkolemInfoAnon
tidySkolemInfoAnon TidyEnv
env1 SkolemInfoAnon
info
implic' :: Implication
implic' = Implication
implic { ic_skols :: [TyCoVar]
ic_skols = [TyCoVar]
tvs'
, ic_given :: [TyCoVar]
ic_given = (TyCoVar -> TyCoVar) -> [TyCoVar] -> [TyCoVar]
forall a b. (a -> b) -> [a] -> [b]
map (TidyEnv -> TyCoVar -> TyCoVar
tidyEvVar TidyEnv
env1) [TyCoVar]
given
, ic_info :: SkolemInfoAnon
ic_info = SkolemInfoAnon
info' }
ctxt1 :: SolverReportErrCtxt
ctxt1 = EvBindsVar -> SolverReportErrCtxt -> SolverReportErrCtxt
maybeSwitchOffDefer EvBindsVar
evb SolverReportErrCtxt
ctxt
ctxt' :: SolverReportErrCtxt
ctxt' = SolverReportErrCtxt
ctxt1 { cec_tidy :: TidyEnv
cec_tidy = TidyEnv
env1
, cec_encl :: [Implication]
cec_encl = Implication
implic' Implication -> [Implication] -> [Implication]
forall a. a -> [a] -> [a]
: SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt
, cec_suppress :: Bool
cec_suppress = Bool
insoluble Bool -> Bool -> Bool
|| SolverReportErrCtxt -> Bool
cec_suppress SolverReportErrCtxt
ctxt
, cec_binds :: EvBindsVar
cec_binds = EvBindsVar
evb }
dead_givens :: [TyCoVar]
dead_givens = case ImplicStatus
status of
IC_Solved { ics_dead :: ImplicStatus -> [TyCoVar]
ics_dead = [TyCoVar]
dead } -> [TyCoVar]
dead
ImplicStatus
_ -> []
bad_telescope :: Bool
bad_telescope = case ImplicStatus
status of
ImplicStatus
IC_BadTelescope -> Bool
True
ImplicStatus
_ -> Bool
False
warnRedundantConstraints :: SolverReportErrCtxt -> TcLclEnv -> SkolemInfoAnon -> [EvVar] -> TcM ()
warnRedundantConstraints :: SolverReportErrCtxt
-> TcLclEnv -> SkolemInfoAnon -> [TyCoVar] -> TcM ()
warnRedundantConstraints SolverReportErrCtxt
ctxt TcLclEnv
env SkolemInfoAnon
info [TyCoVar]
ev_vars
| [TyCoVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TyCoVar]
redundant_evs
= () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| SigSkol UserTypeCtxt
user_ctxt TcType
_ [(Name, TyCoVar)]
_ <- SkolemInfoAnon
info
= TcLclEnv -> TcM () -> TcM ()
forall gbl a.
TcLclEnv -> TcRnIf gbl TcLclEnv a -> TcRnIf gbl TcLclEnv a
restoreLclEnv TcLclEnv
env (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
SrcSpan -> TcM () -> TcM ()
forall a. SrcSpan -> TcRn a -> TcRn a
setSrcSpan (UserTypeCtxt -> SrcSpan
redundantConstraintsSpan UserTypeCtxt
user_ctxt) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
Bool -> TcM ()
report_redundant_msg Bool
True
| Bool
otherwise
= Bool -> TcM ()
report_redundant_msg Bool
False
where
report_redundant_msg :: Bool
-> TcRn ()
report_redundant_msg :: Bool -> TcM ()
report_redundant_msg Bool
show_info
= do { TcLclEnv
lcl_env <- TcRnIf TcGblEnv TcLclEnv TcLclEnv
forall gbl lcl. TcRnIf gbl lcl lcl
getLclEnv
; MsgEnvelope TcRnMessage
msg <-
TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport
TcLclEnv
lcl_env
([TyCoVar] -> (SkolemInfoAnon, Bool) -> TcRnMessage
TcRnRedundantConstraints [TyCoVar]
redundant_evs (SkolemInfoAnon
info, Bool
show_info))
(SolverReportErrCtxt -> Maybe SolverReportErrCtxt
forall a. a -> Maybe a
Just SolverReportErrCtxt
ctxt)
[]
; MsgEnvelope TcRnMessage -> TcM ()
reportDiagnostic MsgEnvelope TcRnMessage
msg }
redundant_evs :: [TyCoVar]
redundant_evs =
(TyCoVar -> Bool) -> [TyCoVar] -> [TyCoVar]
forall a. (a -> Bool) -> [a] -> [a]
filterOut TyCoVar -> Bool
is_type_error ([TyCoVar] -> [TyCoVar]) -> [TyCoVar] -> [TyCoVar]
forall a b. (a -> b) -> a -> b
$
case SkolemInfoAnon
info of
SkolemInfoAnon
InstSkol -> (TyCoVar -> Bool) -> [TyCoVar] -> [TyCoVar]
forall a. (a -> Bool) -> [a] -> [a]
filterOut (TcType -> Bool
improving (TcType -> Bool) -> (TyCoVar -> TcType) -> TyCoVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCoVar -> TcType
idType) [TyCoVar]
ev_vars
SkolemInfoAnon
_ -> [TyCoVar]
ev_vars
is_type_error :: TyCoVar -> Bool
is_type_error = Maybe TcType -> Bool
forall a. Maybe a -> Bool
isJust (Maybe TcType -> Bool)
-> (TyCoVar -> Maybe TcType) -> TyCoVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcType -> Maybe TcType
userTypeError_maybe (TcType -> Maybe TcType)
-> (TyCoVar -> TcType) -> TyCoVar -> Maybe TcType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCoVar -> TcType
idType
improving :: TcType -> Bool
improving TcType
pred
= (TcType -> Bool) -> [TcType] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any TcType -> Bool
isImprovementPred (TcType
pred TcType -> [TcType] -> [TcType]
forall a. a -> [a] -> [a]
: TcType -> [TcType]
transSuperClasses TcType
pred)
reportBadTelescope :: SolverReportErrCtxt -> TcLclEnv -> SkolemInfoAnon -> [TcTyVar] -> TcM ()
reportBadTelescope :: SolverReportErrCtxt
-> TcLclEnv -> SkolemInfoAnon -> [TyCoVar] -> TcM ()
reportBadTelescope SolverReportErrCtxt
ctxt TcLclEnv
env (ForAllSkol TyVarBndrs
telescope) [TyCoVar]
skols
= do { MsgEnvelope TcRnMessage
msg <- TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport
TcLclEnv
env
([SolverReportWithCtxt]
-> DiagnosticReason -> [GhcHint] -> TcRnMessage
TcRnSolverReport [SolverReportWithCtxt
report] DiagnosticReason
ErrorWithoutFlag [GhcHint]
noHints)
(SolverReportErrCtxt -> Maybe SolverReportErrCtxt
forall a. a -> Maybe a
Just SolverReportErrCtxt
ctxt)
[]
; MsgEnvelope TcRnMessage -> TcM ()
reportDiagnostic MsgEnvelope TcRnMessage
msg }
where
report :: SolverReportWithCtxt
report = SolverReportErrCtxt -> TcSolverReportMsg -> SolverReportWithCtxt
SolverReportWithCtxt SolverReportErrCtxt
ctxt (TcSolverReportMsg -> SolverReportWithCtxt)
-> TcSolverReportMsg -> SolverReportWithCtxt
forall a b. (a -> b) -> a -> b
$ TyVarBndrs -> [TyCoVar] -> TcSolverReportMsg
BadTelescope TyVarBndrs
telescope [TyCoVar]
skols
reportBadTelescope SolverReportErrCtxt
_ TcLclEnv
_ SkolemInfoAnon
skol_info [TyCoVar]
skols
= String -> SDoc -> TcM ()
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"reportBadTelescope" (SkolemInfoAnon -> SDoc
forall a. Outputable a => a -> SDoc
ppr SkolemInfoAnon
skol_info SDoc -> SDoc -> SDoc
$$ [TyCoVar] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [TyCoVar]
skols)
ignoreConstraint :: Ct -> Bool
ignoreConstraint :: Ct -> Bool
ignoreConstraint Ct
ct
| CtOrigin
AssocFamPatOrigin <- Ct -> CtOrigin
ctOrigin Ct
ct
= Bool
True
| Bool
otherwise
= Bool
False
mkErrorItem :: Ct -> TcM (Maybe ErrorItem)
mkErrorItem :: Ct -> TcM (Maybe ErrorItem)
mkErrorItem Ct
ct
| Ct -> Bool
ignoreConstraint Ct
ct
= do { String -> SDoc -> TcM ()
traceTc String
"Ignoring constraint:" (Ct -> SDoc
forall a. Outputable a => a -> SDoc
ppr Ct
ct)
; Maybe ErrorItem -> TcM (Maybe ErrorItem)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe ErrorItem
forall a. Maybe a
Nothing }
| Bool
otherwise
= do { let loc :: CtLoc
loc = Ct -> CtLoc
ctLoc Ct
ct
flav :: CtFlavour
flav = Ct -> CtFlavour
ctFlavour Ct
ct
; (Bool
suppress, Maybe TcEvDest
m_evdest) <- case Ct -> CtEvidence
ctEvidence Ct
ct of
CtGiven {} -> (Bool, Maybe TcEvDest)
-> IOEnv (Env TcGblEnv TcLclEnv) (Bool, Maybe TcEvDest)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
False, Maybe TcEvDest
forall a. Maybe a
Nothing)
CtWanted { ctev_rewriters :: CtEvidence -> RewriterSet
ctev_rewriters = RewriterSet
rewriters, ctev_dest :: CtEvidence -> TcEvDest
ctev_dest = TcEvDest
dest }
-> do { Bool
supp <- RewriterSet -> TcRnIf TcGblEnv TcLclEnv Bool
anyUnfilledCoercionHoles RewriterSet
rewriters
; (Bool, Maybe TcEvDest)
-> IOEnv (Env TcGblEnv TcLclEnv) (Bool, Maybe TcEvDest)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
supp, TcEvDest -> Maybe TcEvDest
forall a. a -> Maybe a
Just TcEvDest
dest) }
; let m_reason :: Maybe CtIrredReason
m_reason = case Ct
ct of CIrredCan { cc_reason :: Ct -> CtIrredReason
cc_reason = CtIrredReason
reason } -> CtIrredReason -> Maybe CtIrredReason
forall a. a -> Maybe a
Just CtIrredReason
reason
Ct
_ -> Maybe CtIrredReason
forall a. Maybe a
Nothing
; Maybe ErrorItem -> TcM (Maybe ErrorItem)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe ErrorItem -> TcM (Maybe ErrorItem))
-> Maybe ErrorItem -> TcM (Maybe ErrorItem)
forall a b. (a -> b) -> a -> b
$ ErrorItem -> Maybe ErrorItem
forall a. a -> Maybe a
Just (ErrorItem -> Maybe ErrorItem) -> ErrorItem -> Maybe ErrorItem
forall a b. (a -> b) -> a -> b
$ EI :: TcType
-> Maybe TcEvDest
-> CtFlavour
-> CtLoc
-> Maybe CtIrredReason
-> Bool
-> ErrorItem
EI { ei_pred :: TcType
ei_pred = Ct -> TcType
ctPred Ct
ct
, ei_evdest :: Maybe TcEvDest
ei_evdest = Maybe TcEvDest
m_evdest
, ei_flavour :: CtFlavour
ei_flavour = CtFlavour
flav
, ei_loc :: CtLoc
ei_loc = CtLoc
loc
, ei_m_reason :: Maybe CtIrredReason
ei_m_reason = Maybe CtIrredReason
m_reason
, ei_suppress :: Bool
ei_suppress = Bool
suppress }}
reportWanteds :: SolverReportErrCtxt -> TcLevel -> WantedConstraints -> TcM ()
reportWanteds :: SolverReportErrCtxt -> TcLevel -> WantedConstraints -> TcM ()
reportWanteds SolverReportErrCtxt
ctxt TcLevel
tc_lvl wc :: WantedConstraints
wc@(WC { wc_simple :: WantedConstraints -> Cts
wc_simple = Cts
simples, wc_impl :: WantedConstraints -> Bag Implication
wc_impl = Bag Implication
implics
, wc_holes :: WantedConstraints -> Bag Hole
wc_holes = Bag Hole
holes })
| WantedConstraints -> Bool
isEmptyWC WantedConstraints
wc = String -> SDoc -> TcM ()
traceTc String
"reportWanteds empty WC" SDoc
empty
| Bool
otherwise
= do { [ErrorItem]
tidy_items <- (Ct -> TcM (Maybe ErrorItem))
-> [Ct] -> IOEnv (Env TcGblEnv TcLclEnv) [ErrorItem]
forall (m :: * -> *) a b.
Applicative m =>
(a -> m (Maybe b)) -> [a] -> m [b]
mapMaybeM Ct -> TcM (Maybe ErrorItem)
mkErrorItem [Ct]
tidy_cts
; String -> SDoc -> TcM ()
traceTc String
"reportWanteds 1" ([SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Simples =" SDoc -> SDoc -> SDoc
<+> Cts -> SDoc
forall a. Outputable a => a -> SDoc
ppr Cts
simples
, String -> SDoc
text String
"Suppress =" SDoc -> SDoc -> SDoc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr (SolverReportErrCtxt -> Bool
cec_suppress SolverReportErrCtxt
ctxt)
, String -> SDoc
text String
"tidy_cts =" SDoc -> SDoc -> SDoc
<+> [Ct] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Ct]
tidy_cts
, String -> SDoc
text String
"tidy_items =" SDoc -> SDoc -> SDoc
<+> [ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
tidy_items
, String -> SDoc
text String
"tidy_holes =" SDoc -> SDoc -> SDoc
<+> [Hole] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Hole]
tidy_holes ])
; Bool -> TcM ()
forall (m :: * -> *). (HasCallStack, Applicative m) => Bool -> m ()
massert (Bool -> TcM ()) -> Bool -> TcM ()
forall a b. (a -> b) -> a -> b
$
Cts -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Cts
simples Bool -> Bool -> Bool
||
(Ct -> Bool) -> Cts -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Ct -> Bool
ignoreConstraint Cts
simples Bool -> Bool -> Bool
||
Bool -> Bool
not ((ErrorItem -> Bool) -> [ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ErrorItem -> Bool
ei_suppress [ErrorItem]
tidy_items)
; let ([Hole]
out_of_scope, [Hole]
other_holes) = (Hole -> Bool) -> [Hole] -> ([Hole], [Hole])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition Hole -> Bool
isOutOfScopeHole [Hole]
tidy_holes
ctxt_for_scope_errs :: SolverReportErrCtxt
ctxt_for_scope_errs = SolverReportErrCtxt
ctxt { cec_suppress :: Bool
cec_suppress = Bool
False }
; (()
_, Bool
no_out_of_scope) <- TcM () -> TcRn ((), Bool)
forall a. TcRn a -> TcRn (a, Bool)
askNoErrs (TcM () -> TcRn ((), Bool)) -> TcM () -> TcRn ((), Bool)
forall a b. (a -> b) -> a -> b
$
[ErrorItem] -> SolverReportErrCtxt -> [Hole] -> TcM ()
reportHoles [ErrorItem]
tidy_items SolverReportErrCtxt
ctxt_for_scope_errs [Hole]
out_of_scope
; let ctxt_for_insols :: SolverReportErrCtxt
ctxt_for_insols = SolverReportErrCtxt
ctxt { cec_suppress :: Bool
cec_suppress = Bool -> Bool
not Bool
no_out_of_scope }
; [ErrorItem] -> SolverReportErrCtxt -> [Hole] -> TcM ()
reportHoles [ErrorItem]
tidy_items SolverReportErrCtxt
ctxt_for_insols [Hole]
other_holes
; let ([ErrorItem]
suppressed_items, [ErrorItem]
items0) = (ErrorItem -> Bool) -> [ErrorItem] -> ([ErrorItem], [ErrorItem])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition ErrorItem -> Bool
suppress [ErrorItem]
tidy_items
; String -> SDoc -> TcM ()
traceTc String
"reportWanteds suppressed:" ([ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
suppressed_items)
; (SolverReportErrCtxt
ctxt1, [ErrorItem]
items1) <- SolverReportErrCtxt
-> [ReporterSpec]
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporters SolverReportErrCtxt
ctxt_for_insols [ReporterSpec]
report1 [ErrorItem]
items0
; let ctxt2 :: SolverReportErrCtxt
ctxt2 = SolverReportErrCtxt
ctxt1 { cec_suppress :: Bool
cec_suppress = SolverReportErrCtxt -> Bool
cec_suppress SolverReportErrCtxt
ctxt Bool -> Bool -> Bool
|| SolverReportErrCtxt -> Bool
cec_suppress SolverReportErrCtxt
ctxt1 }
; (SolverReportErrCtxt
ctxt3, [ErrorItem]
leftovers) <- SolverReportErrCtxt
-> [ReporterSpec]
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporters SolverReportErrCtxt
ctxt2 [ReporterSpec]
report2 [ErrorItem]
items1
; Bool -> SDoc -> TcM ()
forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr ([ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ErrorItem]
leftovers)
(String -> SDoc
text String
"The following unsolved Wanted constraints \
\have not been reported to the user:"
SDoc -> SDoc -> SDoc
$$ [ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
leftovers)
; (Implication -> TcM ()) -> Bag Implication -> TcM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> Bag a -> m ()
mapBagM_ (SolverReportErrCtxt -> Implication -> TcM ()
reportImplic SolverReportErrCtxt
ctxt2) Bag Implication
implics
; TcM () -> TcM ()
whenNoErrs (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
do { (SolverReportErrCtxt
_, [ErrorItem]
more_leftovers) <- SolverReportErrCtxt
-> [ReporterSpec]
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporters SolverReportErrCtxt
ctxt3 [ReporterSpec]
forall p. [(String, ErrorItem -> p -> Bool, Bool, Reporter)]
report3 [ErrorItem]
suppressed_items
; Bool -> SDoc -> TcM ()
forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr ([ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ErrorItem]
more_leftovers) ([ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
more_leftovers) } }
where
env :: TidyEnv
env = SolverReportErrCtxt -> TidyEnv
cec_tidy SolverReportErrCtxt
ctxt
tidy_cts :: [Ct]
tidy_cts = Cts -> [Ct]
forall a. Bag a -> [a]
bagToList ((Ct -> Ct) -> Cts -> Cts
forall a b. (a -> b) -> Bag a -> Bag b
mapBag (TidyEnv -> Ct -> Ct
tidyCt TidyEnv
env) Cts
simples)
tidy_holes :: [Hole]
tidy_holes = Bag Hole -> [Hole]
forall a. Bag a -> [a]
bagToList ((Hole -> Hole) -> Bag Hole -> Bag Hole
forall a b. (a -> b) -> Bag a -> Bag b
mapBag (TidyEnv -> Hole -> Hole
tidyHole TidyEnv
env) Bag Hole
holes)
suppress :: ErrorItem -> Bool
suppress :: ErrorItem -> Bool
suppress ErrorItem
item
| CtFlavour
Wanted <- ErrorItem -> CtFlavour
ei_flavour ErrorItem
item
= ErrorItem -> Bool
is_ww_fundep_item ErrorItem
item
| Bool
otherwise
= Bool
False
report1 :: [ReporterSpec]
report1 = [ (String
"custom_error", ErrorItem -> Pred -> Bool
forall p. ErrorItem -> p -> Bool
is_user_type_error, Bool
True, Reporter
mkUserTypeErrorReporter)
, ReporterSpec
given_eq_spec
, (String
"insoluble2", ErrorItem -> Pred -> Bool
forall p. p -> Pred -> Bool
utterly_wrong, Bool
True, (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkEqErr)
, (String
"skolem eq1", ErrorItem -> Pred -> Bool
very_wrong, Bool
True, Reporter
mkSkolReporter)
, (String
"skolem eq2", ErrorItem -> Pred -> Bool
skolem_eq, Bool
True, Reporter
mkSkolReporter)
, (String
"non-tv eq", ErrorItem -> Pred -> Bool
forall p. p -> Pred -> Bool
non_tv_eq, Bool
True, Reporter
mkSkolReporter)
, (String
"Homo eqs", ErrorItem -> Pred -> Bool
is_homo_equality, Bool
True, (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkEqErr)
, (String
"Other eqs", ErrorItem -> Pred -> Bool
is_equality, Bool
True, (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkEqErr)
]
report2 :: [ReporterSpec]
report2 = [ (String
"Implicit params", ErrorItem -> Pred -> Bool
is_ip, Bool
False, (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkIPErr)
, (String
"Irreds", ErrorItem -> Pred -> Bool
is_irred, Bool
False, (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkIrredErr)
, (String
"FixedRuntimeRep", ErrorItem -> Pred -> Bool
is_FRR, Bool
False, (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkFRRErr)
, (String
"Dicts", ErrorItem -> Pred -> Bool
is_dict, Bool
False, (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter HasDebugCallStack =>
SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkDictErr) ]
report3 :: [(String, ErrorItem -> p -> Bool, Bool, Reporter)]
report3 = [ (String
"wanted/wanted fundeps", ErrorItem -> p -> Bool
forall p. ErrorItem -> p -> Bool
is_ww_fundep, Bool
True, (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkEqErr)
]
is_dict, is_equality, is_ip, is_FRR, is_irred :: ErrorItem -> Pred -> Bool
is_given_eq :: ErrorItem -> Pred -> Bool
is_given_eq ErrorItem
item Pred
pred
| CtFlavour
Given <- ErrorItem -> CtFlavour
ei_flavour ErrorItem
item
, EqPred {} <- Pred
pred = Bool
True
| Bool
otherwise = Bool
False
utterly_wrong :: p -> Pred -> Bool
utterly_wrong p
_ (EqPred EqRel
NomEq TcType
ty1 TcType
ty2) = TcType -> Bool
isRigidTy TcType
ty1 Bool -> Bool -> Bool
&& TcType -> Bool
isRigidTy TcType
ty2
utterly_wrong p
_ Pred
_ = Bool
False
very_wrong :: ErrorItem -> Pred -> Bool
very_wrong ErrorItem
_ (EqPred EqRel
NomEq TcType
ty1 TcType
ty2) = TcLevel -> TcType -> Bool
isSkolemTy TcLevel
tc_lvl TcType
ty1 Bool -> Bool -> Bool
&& TcType -> Bool
isRigidTy TcType
ty2
very_wrong ErrorItem
_ Pred
_ = Bool
False
skolem_eq :: ErrorItem -> Pred -> Bool
skolem_eq ErrorItem
_ (EqPred EqRel
NomEq TcType
ty1 TcType
_) = TcLevel -> TcType -> Bool
isSkolemTy TcLevel
tc_lvl TcType
ty1
skolem_eq ErrorItem
_ Pred
_ = Bool
False
non_tv_eq :: p -> Pred -> Bool
non_tv_eq p
_ (EqPred EqRel
NomEq TcType
ty1 TcType
_) = Bool -> Bool
not (TcType -> Bool
isTyVarTy TcType
ty1)
non_tv_eq p
_ Pred
_ = Bool
False
is_user_type_error :: ErrorItem -> p -> Bool
is_user_type_error ErrorItem
item p
_ = TcType -> Bool
isUserTypeError (ErrorItem -> TcType
errorItemPred ErrorItem
item)
is_homo_equality :: ErrorItem -> Pred -> Bool
is_homo_equality ErrorItem
item (EqPred EqRel
_ TcType
ty1 TcType
ty2)
| FixedRuntimeRepOrigin {} <- ErrorItem -> CtOrigin
errorItemOrigin ErrorItem
item
= Bool
False
| Bool
otherwise
= HasDebugCallStack => TcType -> TcType
TcType -> TcType
tcTypeKind TcType
ty1 HasDebugCallStack => TcType -> TcType -> Bool
TcType -> TcType -> Bool
`tcEqType` HasDebugCallStack => TcType -> TcType
TcType -> TcType
tcTypeKind TcType
ty2
is_homo_equality ErrorItem
_ Pred
_
= Bool
False
is_equality :: ErrorItem -> Pred -> Bool
is_equality ErrorItem
item (EqPred {})
| FixedRuntimeRepOrigin {} <- ErrorItem -> CtOrigin
errorItemOrigin ErrorItem
item
= Bool
False
| Bool
otherwise
= Bool
True
is_equality ErrorItem
_ Pred
_
= Bool
False
is_dict :: ErrorItem -> Pred -> Bool
is_dict ErrorItem
_ (ClassPred {}) = Bool
True
is_dict ErrorItem
_ Pred
_ = Bool
False
is_ip :: ErrorItem -> Pred -> Bool
is_ip ErrorItem
_ (ClassPred Class
cls [TcType]
_) = Class -> Bool
isIPClass Class
cls
is_ip ErrorItem
_ Pred
_ = Bool
False
is_FRR :: ErrorItem -> Pred -> Bool
is_FRR ErrorItem
item Pred
_
| FixedRuntimeRepOrigin {} <- ErrorItem -> CtOrigin
errorItemOrigin ErrorItem
item
= Bool
True
is_FRR ErrorItem
_ Pred
_
= Bool
False
is_irred :: ErrorItem -> Pred -> Bool
is_irred ErrorItem
_ (IrredPred {}) = Bool
True
is_irred ErrorItem
_ Pred
_ = Bool
False
is_ww_fundep :: ErrorItem -> p -> Bool
is_ww_fundep ErrorItem
item p
_ = ErrorItem -> Bool
is_ww_fundep_item ErrorItem
item
is_ww_fundep_item :: ErrorItem -> Bool
is_ww_fundep_item = CtOrigin -> Bool
isWantedWantedFunDepOrigin (CtOrigin -> Bool) -> (ErrorItem -> CtOrigin) -> ErrorItem -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorItem -> CtOrigin
errorItemOrigin
given_eq_spec :: ReporterSpec
given_eq_spec
| Bool
has_gadt_match_here
= (String
"insoluble1a", ErrorItem -> Pred -> Bool
is_given_eq, Bool
True, Reporter
mkGivenErrorReporter)
| Bool
otherwise
= (String
"insoluble1b", ErrorItem -> Pred -> Bool
is_given_eq, Bool
False, Reporter
ignoreErrorReporter)
has_gadt_match_here :: Bool
has_gadt_match_here = [Implication] -> Bool
has_gadt_match (SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt)
has_gadt_match :: [Implication] -> Bool
has_gadt_match [] = Bool
False
has_gadt_match (Implication
implic : [Implication]
implics)
| PatSkol {} <- Implication -> SkolemInfoAnon
ic_info Implication
implic
, Implication -> HasGivenEqs
ic_given_eqs Implication
implic HasGivenEqs -> HasGivenEqs -> Bool
forall a. Eq a => a -> a -> Bool
/= HasGivenEqs
NoGivenEqs
, Implication -> Bool
ic_warn_inaccessible Implication
implic
= Bool
True
| Bool
otherwise
= [Implication] -> Bool
has_gadt_match [Implication]
implics
isSkolemTy :: TcLevel -> Type -> Bool
isSkolemTy :: TcLevel -> TcType -> Bool
isSkolemTy TcLevel
tc_lvl TcType
ty
| Just TyCoVar
tv <- TcType -> Maybe TyCoVar
getTyVar_maybe TcType
ty
= TyCoVar -> Bool
isSkolemTyVar TyCoVar
tv
Bool -> Bool -> Bool
|| (TyCoVar -> Bool
isTyVarTyVar TyCoVar
tv Bool -> Bool -> Bool
&& TcLevel -> TyCoVar -> Bool
isTouchableMetaTyVar TcLevel
tc_lvl TyCoVar
tv)
| Bool
otherwise
= Bool
False
isTyFun_maybe :: Type -> Maybe TyCon
isTyFun_maybe :: TcType -> Maybe TyCon
isTyFun_maybe TcType
ty = case HasCallStack => TcType -> Maybe (TyCon, [TcType])
TcType -> Maybe (TyCon, [TcType])
tcSplitTyConApp_maybe TcType
ty of
Just (TyCon
tc,[TcType]
_) | TyCon -> Bool
isTypeFamilyTyCon TyCon
tc -> TyCon -> Maybe TyCon
forall a. a -> Maybe a
Just TyCon
tc
Maybe (TyCon, [TcType])
_ -> Maybe TyCon
forall a. Maybe a
Nothing
type Reporter
= SolverReportErrCtxt -> [ErrorItem] -> TcM ()
type ReporterSpec
= ( String
, ErrorItem -> Pred -> Bool
, Bool
, Reporter)
mkSkolReporter :: Reporter
mkSkolReporter :: Reporter
mkSkolReporter SolverReportErrCtxt
ctxt [ErrorItem]
items
= ([ErrorItem] -> TcM ()) -> [[ErrorItem]] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
reportGroup SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkEqErr SolverReportErrCtxt
ctxt) ([ErrorItem] -> [[ErrorItem]]
group [ErrorItem]
items)
where
group :: [ErrorItem] -> [[ErrorItem]]
group [] = []
group (ErrorItem
item:[ErrorItem]
items) = (ErrorItem
item ErrorItem -> [ErrorItem] -> [ErrorItem]
forall a. a -> [a] -> [a]
: [ErrorItem]
yeses) [ErrorItem] -> [[ErrorItem]] -> [[ErrorItem]]
forall a. a -> [a] -> [a]
: [ErrorItem] -> [[ErrorItem]]
group [ErrorItem]
noes
where
([ErrorItem]
yeses, [ErrorItem]
noes) = (ErrorItem -> Bool) -> [ErrorItem] -> ([ErrorItem], [ErrorItem])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (ErrorItem -> ErrorItem -> Bool
group_with ErrorItem
item) [ErrorItem]
items
group_with :: ErrorItem -> ErrorItem -> Bool
group_with ErrorItem
item1 ErrorItem
item2
| Ordering
EQ <- ErrorItem -> ErrorItem -> Ordering
cmp_loc ErrorItem
item1 ErrorItem
item2 = Bool
True
| ErrorItem -> ErrorItem -> Bool
eq_lhs_type ErrorItem
item1 ErrorItem
item2 = Bool
True
| Bool
otherwise = Bool
False
reportHoles :: [ErrorItem]
-> SolverReportErrCtxt -> [Hole] -> TcM ()
reportHoles :: [ErrorItem] -> SolverReportErrCtxt -> [Hole] -> TcM ()
reportHoles [ErrorItem]
tidy_items SolverReportErrCtxt
ctxt [Hole]
holes
= do
DiagOpts
diag_opts <- DynFlags -> DiagOpts
initDiagOpts (DynFlags -> DiagOpts)
-> IOEnv (Env TcGblEnv TcLclEnv) DynFlags
-> IOEnv (Env TcGblEnv TcLclEnv) DiagOpts
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
let severity :: Severity
severity = DiagOpts -> DiagnosticReason -> Severity
diagReasonSeverity DiagOpts
diag_opts (SolverReportErrCtxt -> DiagnosticReason
cec_type_holes SolverReportErrCtxt
ctxt)
holes' :: [Hole]
holes' = (Hole -> Bool) -> [Hole] -> [Hole]
forall a. (a -> Bool) -> [a] -> [a]
filter (Severity -> Hole -> Bool
keepThisHole Severity
severity) [Hole]
holes
(TidyEnv
tidy_env', NameEnv TcType
lcl_name_cache) <- TidyEnv -> [TcLclEnv] -> TcM (TidyEnv, NameEnv TcType)
zonkTidyTcLclEnvs (SolverReportErrCtxt -> TidyEnv
cec_tidy SolverReportErrCtxt
ctxt) ((Hole -> TcLclEnv) -> [Hole] -> [TcLclEnv]
forall a b. (a -> b) -> [a] -> [b]
map (CtLoc -> TcLclEnv
ctl_env (CtLoc -> TcLclEnv) -> (Hole -> CtLoc) -> Hole -> TcLclEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hole -> CtLoc
hole_loc) [Hole]
holes')
let ctxt' :: SolverReportErrCtxt
ctxt' = SolverReportErrCtxt
ctxt { cec_tidy :: TidyEnv
cec_tidy = TidyEnv
tidy_env' }
[Hole] -> (Hole -> TcM ()) -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Hole]
holes' ((Hole -> TcM ()) -> TcM ()) -> (Hole -> TcM ()) -> TcM ()
forall a b. (a -> b) -> a -> b
$ \Hole
hole -> do { MsgEnvelope TcRnMessage
msg <- NameEnv TcType
-> [ErrorItem]
-> SolverReportErrCtxt
-> Hole
-> TcM (MsgEnvelope TcRnMessage)
mkHoleError NameEnv TcType
lcl_name_cache [ErrorItem]
tidy_items SolverReportErrCtxt
ctxt' Hole
hole
; MsgEnvelope TcRnMessage -> TcM ()
reportDiagnostic MsgEnvelope TcRnMessage
msg }
keepThisHole :: Severity -> Hole -> Bool
keepThisHole :: Severity -> Hole -> Bool
keepThisHole Severity
sev Hole
hole
= case Hole -> HoleSort
hole_sort Hole
hole of
ExprHole {} -> Bool
True
HoleSort
TypeHole -> Bool
keep_type_hole
HoleSort
ConstraintHole -> Bool
keep_type_hole
where
keep_type_hole :: Bool
keep_type_hole = case Severity
sev of
Severity
SevIgnore -> Bool
False
Severity
_ -> Bool
True
zonkTidyTcLclEnvs :: TidyEnv -> [TcLclEnv] -> TcM (TidyEnv, NameEnv Type)
zonkTidyTcLclEnvs :: TidyEnv -> [TcLclEnv] -> TcM (TidyEnv, NameEnv TcType)
zonkTidyTcLclEnvs TidyEnv
tidy_env [TcLclEnv]
lcls = ((TidyEnv, NameEnv TcType)
-> TcBinder -> TcM (TidyEnv, NameEnv TcType))
-> (TidyEnv, NameEnv TcType)
-> [TcBinder]
-> TcM (TidyEnv, NameEnv TcType)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM (TidyEnv, NameEnv TcType)
-> TcBinder -> TcM (TidyEnv, NameEnv TcType)
go (TidyEnv
tidy_env, NameEnv TcType
forall a. NameEnv a
emptyNameEnv) ((TcLclEnv -> [TcBinder]) -> [TcLclEnv] -> [TcBinder]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap TcLclEnv -> [TcBinder]
tcl_bndrs [TcLclEnv]
lcls)
where
go :: (TidyEnv, NameEnv TcType)
-> TcBinder -> TcM (TidyEnv, NameEnv TcType)
go (TidyEnv, NameEnv TcType)
envs TcBinder
tc_bndr = case TcBinder
tc_bndr of
TcTvBndr {} -> (TidyEnv, NameEnv TcType) -> TcM (TidyEnv, NameEnv TcType)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv, NameEnv TcType)
envs
TcIdBndr TyCoVar
id TopLevelFlag
_top_lvl -> Name
-> TcType
-> (TidyEnv, NameEnv TcType)
-> TcM (TidyEnv, NameEnv TcType)
go_one (TyCoVar -> Name
idName TyCoVar
id) (TyCoVar -> TcType
idType TyCoVar
id) (TidyEnv, NameEnv TcType)
envs
TcIdBndr_ExpType Name
name ExpType
et TopLevelFlag
_top_lvl ->
do { Maybe TcType
mb_ty <- ExpType -> TcM (Maybe TcType)
readExpType_maybe ExpType
et
; case Maybe TcType
mb_ty of
Just TcType
ty -> Name
-> TcType
-> (TidyEnv, NameEnv TcType)
-> TcM (TidyEnv, NameEnv TcType)
go_one Name
name TcType
ty (TidyEnv, NameEnv TcType)
envs
Maybe TcType
Nothing -> (TidyEnv, NameEnv TcType) -> TcM (TidyEnv, NameEnv TcType)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv, NameEnv TcType)
envs
}
go_one :: Name
-> TcType
-> (TidyEnv, NameEnv TcType)
-> TcM (TidyEnv, NameEnv TcType)
go_one Name
name TcType
ty (TidyEnv
tidy_env, NameEnv TcType
name_env) = do
if Name
name Name -> NameEnv TcType -> Bool
forall a. Name -> NameEnv a -> Bool
`elemNameEnv` NameEnv TcType
name_env
then (TidyEnv, NameEnv TcType) -> TcM (TidyEnv, NameEnv TcType)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
tidy_env, NameEnv TcType
name_env)
else do
(TidyEnv
tidy_env', TcType
tidy_ty) <- TidyEnv -> TcType -> TcM (TidyEnv, TcType)
zonkTidyTcType TidyEnv
tidy_env TcType
ty
(TidyEnv, NameEnv TcType) -> TcM (TidyEnv, NameEnv TcType)
forall (m :: * -> *) a. Monad m => a -> m a
return (TidyEnv
tidy_env', NameEnv TcType -> Name -> TcType -> NameEnv TcType
forall a. NameEnv a -> Name -> a -> NameEnv a
extendNameEnv NameEnv TcType
name_env Name
name TcType
tidy_ty)
mkUserTypeErrorReporter :: Reporter
mkUserTypeErrorReporter :: Reporter
mkUserTypeErrorReporter SolverReportErrCtxt
ctxt
= (ErrorItem -> TcM ()) -> [ErrorItem] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((ErrorItem -> TcM ()) -> [ErrorItem] -> TcM ())
-> (ErrorItem -> TcM ()) -> [ErrorItem] -> TcM ()
forall a b. (a -> b) -> a -> b
$ \ErrorItem
item -> do { let err :: SolverReport
err = SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important SolverReportErrCtxt
ctxt (TcSolverReportMsg -> SolverReport)
-> TcSolverReportMsg -> SolverReport
forall a b. (a -> b) -> a -> b
$ ErrorItem -> TcSolverReportMsg
mkUserTypeError ErrorItem
item
; SolverReportErrCtxt -> [ErrorItem] -> SolverReport -> TcM ()
maybeReportError SolverReportErrCtxt
ctxt [ErrorItem
item] SolverReport
err
; SolverReportErrCtxt -> SolverReport -> ErrorItem -> TcM ()
addDeferredBinding SolverReportErrCtxt
ctxt SolverReport
err ErrorItem
item }
mkUserTypeError :: ErrorItem -> TcSolverReportMsg
mkUserTypeError :: ErrorItem -> TcSolverReportMsg
mkUserTypeError ErrorItem
item =
case TcType -> Maybe TcType
getUserTypeErrorMsg (ErrorItem -> TcType
errorItemPred ErrorItem
item) of
Just TcType
msg -> TcType -> TcSolverReportMsg
UserTypeError TcType
msg
Maybe TcType
Nothing -> String -> SDoc -> TcSolverReportMsg
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"mkUserTypeError" (ErrorItem -> SDoc
forall a. Outputable a => a -> SDoc
ppr ErrorItem
item)
mkGivenErrorReporter :: Reporter
mkGivenErrorReporter :: Reporter
mkGivenErrorReporter SolverReportErrCtxt
ctxt [ErrorItem]
items
= do { (SolverReportErrCtxt
ctxt, RelevantBindings
relevant_binds, ErrorItem
item) <- Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcM (SolverReportErrCtxt, RelevantBindings, ErrorItem)
relevantBindings Bool
True SolverReportErrCtxt
ctxt ErrorItem
item
; let (Implication
implic:[Implication]
_) = SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt
loc' :: CtLoc
loc' = CtLoc -> TcLclEnv -> CtLoc
setCtLocEnv (ErrorItem -> CtLoc
ei_loc ErrorItem
item) (Implication -> TcLclEnv
ic_env Implication
implic)
item' :: ErrorItem
item' = ErrorItem
item { ei_loc :: CtLoc
ei_loc = CtLoc
loc' }
; (AccReportMsgs
eq_err_msgs, [GhcHint]
_hints) <- SolverReportErrCtxt
-> ErrorItem -> TcType -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkEqErr_help SolverReportErrCtxt
ctxt ErrorItem
item' TcType
ty1 TcType
ty2
; let supplementary :: [SolverReportSupplementary]
supplementary = [ RelevantBindings -> SolverReportSupplementary
SupplementaryBindings RelevantBindings
relevant_binds ]
msg :: TcRnMessage
msg = Implication -> NonEmpty SolverReportWithCtxt -> TcRnMessage
TcRnInaccessibleCode Implication
implic (NonEmpty SolverReportWithCtxt -> NonEmpty SolverReportWithCtxt
forall a. NonEmpty a -> NonEmpty a
NE.reverse (NonEmpty SolverReportWithCtxt -> NonEmpty SolverReportWithCtxt)
-> (AccReportMsgs -> NonEmpty SolverReportWithCtxt)
-> AccReportMsgs
-> NonEmpty SolverReportWithCtxt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TcSolverReportMsg -> SolverReportWithCtxt)
-> AccReportMsgs -> NonEmpty SolverReportWithCtxt
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
NE.map (SolverReportErrCtxt -> TcSolverReportMsg -> SolverReportWithCtxt
SolverReportWithCtxt SolverReportErrCtxt
ctxt) (AccReportMsgs -> NonEmpty SolverReportWithCtxt)
-> AccReportMsgs -> NonEmpty SolverReportWithCtxt
forall a b. (a -> b) -> a -> b
$ AccReportMsgs
eq_err_msgs)
; MsgEnvelope TcRnMessage
msg <- TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport (CtLoc -> TcLclEnv
ctLocEnv CtLoc
loc') TcRnMessage
msg (SolverReportErrCtxt -> Maybe SolverReportErrCtxt
forall a. a -> Maybe a
Just SolverReportErrCtxt
ctxt) [SolverReportSupplementary]
supplementary
; MsgEnvelope TcRnMessage -> TcM ()
reportDiagnostic MsgEnvelope TcRnMessage
msg }
where
(ErrorItem
item : [ErrorItem]
_ ) = [ErrorItem]
items
(TcType
ty1, TcType
ty2) = TcType -> (TcType, TcType)
getEqPredTys (ErrorItem -> TcType
errorItemPred ErrorItem
item)
ignoreErrorReporter :: Reporter
ignoreErrorReporter :: Reporter
ignoreErrorReporter SolverReportErrCtxt
ctxt [ErrorItem]
items
= do { String -> SDoc -> TcM ()
traceTc String
"mkGivenErrorReporter no" ([ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
items SDoc -> SDoc -> SDoc
$$ [Implication] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt))
; () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
return () }
mkGroupReporter :: (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter :: (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
mkGroupReporter SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mk_err SolverReportErrCtxt
ctxt [ErrorItem]
items
= (NonEmpty ErrorItem -> TcM ()) -> [NonEmpty ErrorItem] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
reportGroup SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mk_err SolverReportErrCtxt
ctxt ([ErrorItem] -> TcM ())
-> (NonEmpty ErrorItem -> [ErrorItem])
-> NonEmpty ErrorItem
-> TcM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty ErrorItem -> [ErrorItem]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList) ((ErrorItem -> ErrorItem -> Ordering)
-> [ErrorItem] -> [NonEmpty ErrorItem]
forall a. (a -> a -> Ordering) -> [a] -> [NonEmpty a]
equivClasses ErrorItem -> ErrorItem -> Ordering
cmp_loc [ErrorItem]
items)
eq_lhs_type :: ErrorItem -> ErrorItem -> Bool
eq_lhs_type :: ErrorItem -> ErrorItem -> Bool
eq_lhs_type ErrorItem
item1 ErrorItem
item2
= case (TcType -> Pred
classifyPredType (ErrorItem -> TcType
errorItemPred ErrorItem
item1), TcType -> Pred
classifyPredType (ErrorItem -> TcType
errorItemPred ErrorItem
item2)) of
(EqPred EqRel
eq_rel1 TcType
ty1 TcType
_, EqPred EqRel
eq_rel2 TcType
ty2 TcType
_) ->
(EqRel
eq_rel1 EqRel -> EqRel -> Bool
forall a. Eq a => a -> a -> Bool
== EqRel
eq_rel2) Bool -> Bool -> Bool
&& (TcType
ty1 TcType -> TcType -> Bool
`eqType` TcType
ty2)
(Pred, Pred)
_ -> String -> SDoc -> Bool
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"mkSkolReporter" (ErrorItem -> SDoc
forall a. Outputable a => a -> SDoc
ppr ErrorItem
item1 SDoc -> SDoc -> SDoc
$$ ErrorItem -> SDoc
forall a. Outputable a => a -> SDoc
ppr ErrorItem
item2)
cmp_loc :: ErrorItem -> ErrorItem -> Ordering
cmp_loc :: ErrorItem -> ErrorItem -> Ordering
cmp_loc ErrorItem
item1 ErrorItem
item2 = ErrorItem -> RealSrcLoc
get ErrorItem
item1 RealSrcLoc -> RealSrcLoc -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` ErrorItem -> RealSrcLoc
get ErrorItem
item2
where
get :: ErrorItem -> RealSrcLoc
get ErrorItem
ei = RealSrcSpan -> RealSrcLoc
realSrcSpanStart (CtLoc -> RealSrcSpan
ctLocSpan (ErrorItem -> CtLoc
errorItemCtLoc ErrorItem
ei))
reportGroup :: (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport) -> Reporter
reportGroup :: (SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport)
-> Reporter
reportGroup SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mk_err SolverReportErrCtxt
ctxt [ErrorItem]
items
= do { SolverReport
err <- SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mk_err SolverReportErrCtxt
ctxt [ErrorItem]
items
; String -> SDoc -> TcM ()
traceTc String
"About to maybeReportErr" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Constraint:" SDoc -> SDoc -> SDoc
<+> [ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
items
, String -> SDoc
text String
"cec_suppress =" SDoc -> SDoc -> SDoc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr (SolverReportErrCtxt -> Bool
cec_suppress SolverReportErrCtxt
ctxt)
, String -> SDoc
text String
"cec_defer_type_errors =" SDoc -> SDoc -> SDoc
<+> DiagnosticReason -> SDoc
forall a. Outputable a => a -> SDoc
ppr (SolverReportErrCtxt -> DiagnosticReason
cec_defer_type_errors SolverReportErrCtxt
ctxt) ]
; SolverReportErrCtxt -> [ErrorItem] -> SolverReport -> TcM ()
maybeReportError SolverReportErrCtxt
ctxt [ErrorItem]
items SolverReport
err
; String -> SDoc -> TcM ()
traceTc String
"reportGroup" ([ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
items)
; (ErrorItem -> TcM ()) -> [ErrorItem] -> TcM ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (SolverReportErrCtxt -> SolverReport -> ErrorItem -> TcM ()
addDeferredBinding SolverReportErrCtxt
ctxt SolverReport
err) [ErrorItem]
items }
nonDeferrableOrigin :: CtOrigin -> Bool
nonDeferrableOrigin :: CtOrigin -> Bool
nonDeferrableOrigin CtOrigin
NonLinearPatternOrigin = Bool
True
nonDeferrableOrigin (UsageEnvironmentOf {}) = Bool
True
nonDeferrableOrigin (FixedRuntimeRepOrigin {}) = Bool
True
nonDeferrableOrigin CtOrigin
_ = Bool
False
maybeReportError :: SolverReportErrCtxt
-> [ErrorItem]
-> SolverReport -> TcM ()
maybeReportError :: SolverReportErrCtxt -> [ErrorItem] -> SolverReport -> TcM ()
maybeReportError SolverReportErrCtxt
ctxt items :: [ErrorItem]
items@(ErrorItem
item1:[ErrorItem]
_) (SolverReport { sr_important_msgs :: SolverReport -> [SolverReportWithCtxt]
sr_important_msgs = [SolverReportWithCtxt]
important
, sr_supplementary :: SolverReport -> [SolverReportSupplementary]
sr_supplementary = [SolverReportSupplementary]
supp
, sr_hints :: SolverReport -> [GhcHint]
sr_hints = [GhcHint]
hints })
= Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (SolverReportErrCtxt -> Bool
cec_suppress SolverReportErrCtxt
ctxt
Bool -> Bool -> Bool
|| (ErrorItem -> Bool) -> [ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all ErrorItem -> Bool
ei_suppress [ErrorItem]
items) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$
do let reason :: DiagnosticReason
reason | (ErrorItem -> Bool) -> [ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (CtOrigin -> Bool
nonDeferrableOrigin (CtOrigin -> Bool) -> (ErrorItem -> CtOrigin) -> ErrorItem -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorItem -> CtOrigin
errorItemOrigin) [ErrorItem]
items = DiagnosticReason
ErrorWithoutFlag
| Bool
otherwise = SolverReportErrCtxt -> DiagnosticReason
cec_defer_type_errors SolverReportErrCtxt
ctxt
diag :: TcRnMessage
diag = [SolverReportWithCtxt]
-> DiagnosticReason -> [GhcHint] -> TcRnMessage
TcRnSolverReport [SolverReportWithCtxt]
important DiagnosticReason
reason [GhcHint]
hints
MsgEnvelope TcRnMessage
msg <- TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport (CtLoc -> TcLclEnv
ctLocEnv (ErrorItem -> CtLoc
errorItemCtLoc ErrorItem
item1)) TcRnMessage
diag (SolverReportErrCtxt -> Maybe SolverReportErrCtxt
forall a. a -> Maybe a
Just SolverReportErrCtxt
ctxt) [SolverReportSupplementary]
supp
MsgEnvelope TcRnMessage -> TcM ()
reportDiagnostic MsgEnvelope TcRnMessage
msg
maybeReportError SolverReportErrCtxt
_ [ErrorItem]
_ SolverReport
_ = String -> TcM ()
forall a. String -> a
panic String
"maybeReportError"
addDeferredBinding :: SolverReportErrCtxt -> SolverReport -> ErrorItem -> TcM ()
addDeferredBinding :: SolverReportErrCtxt -> SolverReport -> ErrorItem -> TcM ()
addDeferredBinding SolverReportErrCtxt
ctxt SolverReport
err (EI { ei_evdest :: ErrorItem -> Maybe TcEvDest
ei_evdest = Just TcEvDest
dest, ei_pred :: ErrorItem -> TcType
ei_pred = TcType
item_ty
, ei_loc :: ErrorItem -> CtLoc
ei_loc = CtLoc
loc })
| SolverReportErrCtxt -> Bool
deferringAnyBindings SolverReportErrCtxt
ctxt
= do { EvTerm
err_tm <- SolverReportErrCtxt
-> CtLoc -> TcType -> SolverReport -> TcM EvTerm
mkErrorTerm SolverReportErrCtxt
ctxt CtLoc
loc TcType
item_ty SolverReport
err
; let ev_binds_var :: EvBindsVar
ev_binds_var = SolverReportErrCtxt -> EvBindsVar
cec_binds SolverReportErrCtxt
ctxt
; case TcEvDest
dest of
EvVarDest TyCoVar
evar
-> EvBindsVar -> EvBind -> TcM ()
addTcEvBind EvBindsVar
ev_binds_var (EvBind -> TcM ()) -> EvBind -> TcM ()
forall a b. (a -> b) -> a -> b
$ TyCoVar -> EvTerm -> EvBind
mkWantedEvBind TyCoVar
evar EvTerm
err_tm
HoleDest CoercionHole
hole
-> do {
let co_var :: TyCoVar
co_var = CoercionHole -> TyCoVar
coHoleCoVar CoercionHole
hole
; EvBindsVar -> EvBind -> TcM ()
addTcEvBind EvBindsVar
ev_binds_var (EvBind -> TcM ()) -> EvBind -> TcM ()
forall a b. (a -> b) -> a -> b
$ TyCoVar -> EvTerm -> EvBind
mkWantedEvBind TyCoVar
co_var EvTerm
err_tm
; CoercionHole -> Coercion -> TcM ()
fillCoercionHole CoercionHole
hole (TyCoVar -> Coercion
mkTcCoVarCo TyCoVar
co_var) }
TcEvDest
NoDest
-> () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
return () }
addDeferredBinding SolverReportErrCtxt
_ SolverReport
_ ErrorItem
_ = () -> TcM ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
mkErrorTerm :: SolverReportErrCtxt -> CtLoc -> Type
-> SolverReport -> TcM EvTerm
mkErrorTerm :: SolverReportErrCtxt
-> CtLoc -> TcType -> SolverReport -> TcM EvTerm
mkErrorTerm SolverReportErrCtxt
ctxt CtLoc
ct_loc TcType
ty (SolverReport { sr_important_msgs :: SolverReport -> [SolverReportWithCtxt]
sr_important_msgs = [SolverReportWithCtxt]
important, sr_supplementary :: SolverReport -> [SolverReportSupplementary]
sr_supplementary = [SolverReportSupplementary]
supp })
= do { MsgEnvelope TcRnMessage
msg <- TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport
(CtLoc -> TcLclEnv
ctLocEnv CtLoc
ct_loc)
([SolverReportWithCtxt]
-> DiagnosticReason -> [GhcHint] -> TcRnMessage
TcRnSolverReport [SolverReportWithCtxt]
important DiagnosticReason
ErrorWithoutFlag [GhcHint]
noHints) (SolverReportErrCtxt -> Maybe SolverReportErrCtxt
forall a. a -> Maybe a
Just SolverReportErrCtxt
ctxt) [SolverReportSupplementary]
supp
; DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; let err_msg :: SDoc
err_msg = MsgEnvelope TcRnMessage -> SDoc
forall e. Diagnostic e => MsgEnvelope e -> SDoc
pprLocMsgEnvelope MsgEnvelope TcRnMessage
msg
err_str :: String
err_str = DynFlags -> SDoc -> String
showSDoc DynFlags
dflags (SDoc -> String) -> SDoc -> String
forall a b. (a -> b) -> a -> b
$
SDoc
err_msg SDoc -> SDoc -> SDoc
$$ String -> SDoc
text String
"(deferred type error)"
; EvTerm -> TcM EvTerm
forall (m :: * -> *) a. Monad m => a -> m a
return (EvTerm -> TcM EvTerm) -> EvTerm -> TcM EvTerm
forall a b. (a -> b) -> a -> b
$ TcType -> String -> EvTerm
evDelayedError TcType
ty String
err_str }
tryReporters :: SolverReportErrCtxt -> [ReporterSpec] -> [ErrorItem] -> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporters :: SolverReportErrCtxt
-> [ReporterSpec]
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporters SolverReportErrCtxt
ctxt [ReporterSpec]
reporters [ErrorItem]
items
= do { let ([ErrorItem]
vis_items, [ErrorItem]
invis_items)
= (ErrorItem -> Bool) -> [ErrorItem] -> ([ErrorItem], [ErrorItem])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (CtOrigin -> Bool
isVisibleOrigin (CtOrigin -> Bool) -> (ErrorItem -> CtOrigin) -> ErrorItem -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorItem -> CtOrigin
errorItemOrigin) [ErrorItem]
items
; String -> SDoc -> TcM ()
traceTc String
"tryReporters {" ([ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
vis_items SDoc -> SDoc -> SDoc
$$ [ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
invis_items)
; (SolverReportErrCtxt
ctxt', [ErrorItem]
items') <- SolverReportErrCtxt
-> [ReporterSpec]
-> [ErrorItem]
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
go SolverReportErrCtxt
ctxt [ReporterSpec]
reporters [ErrorItem]
vis_items [ErrorItem]
invis_items
; String -> SDoc -> TcM ()
traceTc String
"tryReporters }" ([ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
items')
; (SolverReportErrCtxt, [ErrorItem])
-> TcM (SolverReportErrCtxt, [ErrorItem])
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
ctxt', [ErrorItem]
items') }
where
go :: SolverReportErrCtxt
-> [ReporterSpec]
-> [ErrorItem]
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
go SolverReportErrCtxt
ctxt [] [ErrorItem]
vis_items [ErrorItem]
invis_items
= (SolverReportErrCtxt, [ErrorItem])
-> TcM (SolverReportErrCtxt, [ErrorItem])
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
ctxt, [ErrorItem]
vis_items [ErrorItem] -> [ErrorItem] -> [ErrorItem]
forall a. [a] -> [a] -> [a]
++ [ErrorItem]
invis_items)
go SolverReportErrCtxt
ctxt (ReporterSpec
r : [ReporterSpec]
rs) [ErrorItem]
vis_items [ErrorItem]
invis_items
= do { (SolverReportErrCtxt
ctxt', [ErrorItem]
vis_items') <- SolverReportErrCtxt
-> ReporterSpec
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporter SolverReportErrCtxt
ctxt ReporterSpec
r [ErrorItem]
vis_items
; (SolverReportErrCtxt
ctxt'', [ErrorItem]
invis_items') <- SolverReportErrCtxt
-> ReporterSpec
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporter SolverReportErrCtxt
ctxt' ReporterSpec
r [ErrorItem]
invis_items
; SolverReportErrCtxt
-> [ReporterSpec]
-> [ErrorItem]
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
go SolverReportErrCtxt
ctxt'' [ReporterSpec]
rs [ErrorItem]
vis_items' [ErrorItem]
invis_items' }
tryReporter :: SolverReportErrCtxt -> ReporterSpec -> [ErrorItem] -> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporter :: SolverReportErrCtxt
-> ReporterSpec
-> [ErrorItem]
-> TcM (SolverReportErrCtxt, [ErrorItem])
tryReporter SolverReportErrCtxt
ctxt (String
str, ErrorItem -> Pred -> Bool
keep_me, Bool
suppress_after, Reporter
reporter) [ErrorItem]
items
| [ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ErrorItem]
yeses
= (SolverReportErrCtxt, [ErrorItem])
-> TcM (SolverReportErrCtxt, [ErrorItem])
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
ctxt, [ErrorItem]
items)
| Bool
otherwise
= do { String -> SDoc -> TcM ()
traceTc String
"tryReporter{ " (String -> SDoc
text String
str SDoc -> SDoc -> SDoc
<+> [ErrorItem] -> SDoc
forall a. Outputable a => a -> SDoc
ppr [ErrorItem]
yeses)
; (()
_, Bool
no_errs) <- TcM () -> TcRn ((), Bool)
forall a. TcRn a -> TcRn (a, Bool)
askNoErrs (Reporter
reporter SolverReportErrCtxt
ctxt [ErrorItem]
yeses)
; let suppress_now :: Bool
suppress_now = Bool -> Bool
not Bool
no_errs Bool -> Bool -> Bool
&& Bool
suppress_after
ctxt' :: SolverReportErrCtxt
ctxt' = SolverReportErrCtxt
ctxt { cec_suppress :: Bool
cec_suppress = Bool
suppress_now Bool -> Bool -> Bool
|| SolverReportErrCtxt -> Bool
cec_suppress SolverReportErrCtxt
ctxt }
; String -> SDoc -> TcM ()
traceTc String
"tryReporter end }" (String -> SDoc
text String
str SDoc -> SDoc -> SDoc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr (SolverReportErrCtxt -> Bool
cec_suppress SolverReportErrCtxt
ctxt) SDoc -> SDoc -> SDoc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
suppress_after)
; (SolverReportErrCtxt, [ErrorItem])
-> TcM (SolverReportErrCtxt, [ErrorItem])
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
ctxt', [ErrorItem]
nos) }
where
([ErrorItem]
yeses, [ErrorItem]
nos) = (ErrorItem -> Bool) -> [ErrorItem] -> ([ErrorItem], [ErrorItem])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition ErrorItem -> Bool
keep [ErrorItem]
items
keep :: ErrorItem -> Bool
keep ErrorItem
item = ErrorItem -> Pred -> Bool
keep_me ErrorItem
item (TcType -> Pred
classifyPredType (ErrorItem -> TcType
errorItemPred ErrorItem
item))
mkErrorReport :: TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport :: TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport TcLclEnv
tcl_env TcRnMessage
msg Maybe SolverReportErrCtxt
mb_ctxt [SolverReportSupplementary]
supplementary
= do { Maybe SDoc
mb_context <- (SolverReportErrCtxt -> IOEnv (Env TcGblEnv TcLclEnv) SDoc)
-> Maybe SolverReportErrCtxt
-> IOEnv (Env TcGblEnv TcLclEnv) (Maybe SDoc)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (\ SolverReportErrCtxt
ctxt -> TidyEnv -> [ErrCtxt] -> IOEnv (Env TcGblEnv TcLclEnv) SDoc
mkErrInfo (SolverReportErrCtxt -> TidyEnv
cec_tidy SolverReportErrCtxt
ctxt) (TcLclEnv -> [ErrCtxt]
tcl_ctxt TcLclEnv
tcl_env)) Maybe SolverReportErrCtxt
mb_ctxt
; UnitState
unit_state <- HasDebugCallStack => HscEnv -> UnitState
HscEnv -> UnitState
hsc_units (HscEnv -> UnitState)
-> IOEnv (Env TcGblEnv TcLclEnv) HscEnv
-> IOEnv (Env TcGblEnv TcLclEnv) UnitState
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IOEnv (Env TcGblEnv TcLclEnv) HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
; HoleFitDispConfig
hfdc <- TcM HoleFitDispConfig
getHoleFitDispConfig
; let
err_info :: ErrInfo
err_info =
SDoc -> SDoc -> ErrInfo
ErrInfo
(SDoc -> Maybe SDoc -> SDoc
forall a. a -> Maybe a -> a
fromMaybe SDoc
empty Maybe SDoc
mb_context)
([SDoc] -> SDoc
vcat ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ (SolverReportSupplementary -> SDoc)
-> [SolverReportSupplementary] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (HoleFitDispConfig -> SolverReportSupplementary -> SDoc
pprSolverReportSupplementary HoleFitDispConfig
hfdc) [SolverReportSupplementary]
supplementary)
; SrcSpan -> TcRnMessage -> TcM (MsgEnvelope TcRnMessage)
mkTcRnMessage
(RealSrcSpan -> Maybe BufSpan -> SrcSpan
RealSrcSpan (TcLclEnv -> RealSrcSpan
tcl_loc TcLclEnv
tcl_env) Maybe BufSpan
forall a. Maybe a
Strict.Nothing)
(UnitState -> TcRnMessageDetailed -> TcRnMessage
TcRnMessageWithInfo UnitState
unit_state (TcRnMessageDetailed -> TcRnMessage)
-> TcRnMessageDetailed -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ ErrInfo -> TcRnMessage -> TcRnMessageDetailed
TcRnMessageDetailed ErrInfo
err_info TcRnMessage
msg) }
pprSolverReportSupplementary :: HoleFitDispConfig -> SolverReportSupplementary -> SDoc
pprSolverReportSupplementary :: HoleFitDispConfig -> SolverReportSupplementary -> SDoc
pprSolverReportSupplementary HoleFitDispConfig
hfdc = \case
SupplementaryBindings RelevantBindings
binds -> RelevantBindings -> SDoc
pprRelevantBindings RelevantBindings
binds
SupplementaryHoleFits ValidHoleFits
fits -> HoleFitDispConfig -> ValidHoleFits -> SDoc
pprValidHoleFits HoleFitDispConfig
hfdc ValidHoleFits
fits
SupplementaryCts [(TcType, RealSrcSpan)]
cts -> [(TcType, RealSrcSpan)] -> SDoc
pprConstraintsInclude [(TcType, RealSrcSpan)]
cts
pprValidHoleFits :: HoleFitDispConfig -> ValidHoleFits -> SDoc
pprValidHoleFits :: HoleFitDispConfig -> ValidHoleFits -> SDoc
pprValidHoleFits HoleFitDispConfig
hfdc (ValidHoleFits (Fits [HoleFit]
fits Bool
discarded_fits) (Fits [HoleFit]
refs Bool
discarded_refs))
= SDoc
fits_msg SDoc -> SDoc -> SDoc
$$ SDoc
refs_msg
where
fits_msg, refs_msg, fits_discard_msg, refs_discard_msg :: SDoc
fits_msg :: SDoc
fits_msg = Bool -> SDoc -> SDoc
ppUnless ([HoleFit] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [HoleFit]
fits) (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Valid hole fits include") Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
vcat ((HoleFit -> SDoc) -> [HoleFit] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (HoleFitDispConfig -> HoleFit -> SDoc
pprHoleFit HoleFitDispConfig
hfdc) [HoleFit]
fits)
SDoc -> SDoc -> SDoc
$$ Bool -> SDoc -> SDoc
ppWhen Bool
discarded_fits SDoc
fits_discard_msg
refs_msg :: SDoc
refs_msg = Bool -> SDoc -> SDoc
ppUnless ([HoleFit] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [HoleFit]
refs) (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Valid refinement hole fits include") Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
vcat ((HoleFit -> SDoc) -> [HoleFit] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (HoleFitDispConfig -> HoleFit -> SDoc
pprHoleFit HoleFitDispConfig
hfdc) [HoleFit]
refs)
SDoc -> SDoc -> SDoc
$$ Bool -> SDoc -> SDoc
ppWhen Bool
discarded_refs SDoc
refs_discard_msg
fits_discard_msg :: SDoc
fits_discard_msg =
String -> SDoc
text String
"(Some hole fits suppressed;" SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"use -fmax-valid-hole-fits=N" SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"or -fno-max-valid-hole-fits)"
refs_discard_msg :: SDoc
refs_discard_msg =
String -> SDoc
text String
"(Some refinement hole fits suppressed;" SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"use -fmax-refinement-hole-fits=N" SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"or -fno-max-refinement-hole-fits)"
pprConstraintsInclude :: [(PredType, RealSrcSpan)] -> SDoc
pprConstraintsInclude :: [(TcType, RealSrcSpan)] -> SDoc
pprConstraintsInclude [(TcType, RealSrcSpan)]
cts
= Bool -> SDoc -> SDoc
ppUnless ([(TcType, RealSrcSpan)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(TcType, RealSrcSpan)]
cts) (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$
SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Constraints include")
Int
2 ([SDoc] -> SDoc
vcat ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ ((TcType, RealSrcSpan) -> SDoc)
-> [(TcType, RealSrcSpan)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (TcType, RealSrcSpan) -> SDoc
forall a a. (Outputable a, Outputable a) => (a, a) -> SDoc
pprConstraint [(TcType, RealSrcSpan)]
cts)
where
pprConstraint :: (a, a) -> SDoc
pprConstraint (a
constraint, a
loc) =
a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
constraint SDoc -> SDoc -> SDoc
<+> Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc
parens (String -> SDoc
text String
"from" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
loc))
mkIrredErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkIrredErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkIrredErr SolverReportErrCtxt
ctxt [ErrorItem]
items
= do { (SolverReportErrCtxt
ctxt, RelevantBindings
binds_msg, ErrorItem
item1) <- Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcM (SolverReportErrCtxt, RelevantBindings, ErrorItem)
relevantBindings Bool
True SolverReportErrCtxt
ctxt ErrorItem
item1
; let msg :: SolverReport
msg = SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important SolverReportErrCtxt
ctxt (TcSolverReportMsg -> SolverReport)
-> TcSolverReportMsg -> SolverReport
forall a b. (a -> b) -> a -> b
$
[Implication]
-> NonEmpty ErrorItem -> Maybe CND_Extra -> TcSolverReportMsg
CouldNotDeduce (SolverReportErrCtxt -> [Implication]
getUserGivens SolverReportErrCtxt
ctxt) (ErrorItem
item1 ErrorItem -> [ErrorItem] -> NonEmpty ErrorItem
forall a. a -> [a] -> NonEmpty a
:| [ErrorItem]
others) Maybe CND_Extra
forall a. Maybe a
Nothing
; SolverReport -> TcM SolverReport
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReport -> TcM SolverReport)
-> SolverReport -> TcM SolverReport
forall a b. (a -> b) -> a -> b
$ SolverReport
msg SolverReport -> SolverReport -> SolverReport
forall a. Monoid a => a -> a -> a
`mappend` RelevantBindings -> SolverReport
mk_relevant_bindings RelevantBindings
binds_msg }
where
(ErrorItem
item1:[ErrorItem]
others) = [ErrorItem]
final_items
filtered_items :: [ErrorItem]
filtered_items = (ErrorItem -> Bool) -> [ErrorItem] -> [ErrorItem]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (ErrorItem -> Bool) -> ErrorItem -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorItem -> Bool
ei_suppress) [ErrorItem]
items
final_items :: [ErrorItem]
final_items | [ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ErrorItem]
filtered_items = [ErrorItem]
items
| Bool
otherwise = [ErrorItem]
filtered_items
mkHoleError :: NameEnv Type -> [ErrorItem] -> SolverReportErrCtxt -> Hole -> TcM (MsgEnvelope TcRnMessage)
mkHoleError :: NameEnv TcType
-> [ErrorItem]
-> SolverReportErrCtxt
-> Hole
-> TcM (MsgEnvelope TcRnMessage)
mkHoleError NameEnv TcType
_ [ErrorItem]
_tidy_simples SolverReportErrCtxt
ctxt hole :: Hole
hole@(Hole { hole_occ :: Hole -> OccName
hole_occ = OccName
occ, hole_loc :: Hole -> CtLoc
hole_loc = CtLoc
ct_loc })
| Hole -> Bool
isOutOfScopeHole Hole
hole
= do { DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; GlobalRdrEnv
rdr_env <- TcRn GlobalRdrEnv
getGlobalRdrEnv
; ImportAvails
imp_info <- TcRn ImportAvails
getImports
; Module
curr_mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; HomePackageTable
hpt <- TcRnIf TcGblEnv TcLclEnv HomePackageTable
forall gbl lcl. TcRnIf gbl lcl HomePackageTable
getHpt
; let ([ImportError]
imp_errs, [GhcHint]
hints)
= WhatLooking
-> DynFlags
-> HomePackageTable
-> Module
-> GlobalRdrEnv
-> LocalRdrEnv
-> ImportAvails
-> RdrName
-> ([ImportError], [GhcHint])
unknownNameSuggestions WhatLooking
WL_Anything
DynFlags
dflags HomePackageTable
hpt Module
curr_mod GlobalRdrEnv
rdr_env
(TcLclEnv -> LocalRdrEnv
tcl_rdr TcLclEnv
lcl_env) ImportAvails
imp_info (OccName -> RdrName
mkRdrUnqual OccName
occ)
errs :: [SolverReportWithCtxt]
errs = [SolverReportErrCtxt -> TcSolverReportMsg -> SolverReportWithCtxt
SolverReportWithCtxt SolverReportErrCtxt
ctxt (Hole -> HoleError -> TcSolverReportMsg
ReportHoleError Hole
hole (HoleError -> TcSolverReportMsg) -> HoleError -> TcSolverReportMsg
forall a b. (a -> b) -> a -> b
$ [ImportError] -> HoleError
OutOfScopeHole [ImportError]
imp_errs)]
report :: SolverReport
report = [SolverReportWithCtxt]
-> [SolverReportSupplementary] -> [GhcHint] -> SolverReport
SolverReport [SolverReportWithCtxt]
errs [] [GhcHint]
hints
; SolverReportErrCtxt -> Hole -> SolverReport -> TcM ()
maybeAddDeferredBindings SolverReportErrCtxt
ctxt Hole
hole SolverReport
report
; TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport TcLclEnv
lcl_env ([SolverReportWithCtxt]
-> DiagnosticReason -> [GhcHint] -> TcRnMessage
TcRnSolverReport [SolverReportWithCtxt]
errs (SolverReportErrCtxt -> DiagnosticReason
cec_out_of_scope_holes SolverReportErrCtxt
ctxt) [GhcHint]
hints) Maybe SolverReportErrCtxt
forall a. Maybe a
Nothing []
}
where
lcl_env :: TcLclEnv
lcl_env = CtLoc -> TcLclEnv
ctLocEnv CtLoc
ct_loc
mkHoleError NameEnv TcType
lcl_name_cache [ErrorItem]
tidy_simples SolverReportErrCtxt
ctxt
hole :: Hole
hole@(Hole { hole_ty :: Hole -> TcType
hole_ty = TcType
hole_ty
, hole_sort :: Hole -> HoleSort
hole_sort = HoleSort
sort
, hole_loc :: Hole -> CtLoc
hole_loc = CtLoc
ct_loc })
= do { RelevantBindings
rel_binds
<- Bool
-> TcLclEnv -> NameEnv TcType -> TyCoVarSet -> TcM RelevantBindings
relevant_bindings Bool
False TcLclEnv
lcl_env NameEnv TcType
lcl_name_cache (TcType -> TyCoVarSet
tyCoVarsOfType TcType
hole_ty)
; Bool
show_hole_constraints <- GeneralFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_ShowHoleConstraints
; let relevant_cts :: [(TcType, RealSrcSpan)]
relevant_cts
| ExprHole HoleExprRef
_ <- HoleSort
sort, Bool
show_hole_constraints
= SolverReportErrCtxt -> [(TcType, RealSrcSpan)]
givenConstraints SolverReportErrCtxt
ctxt
| Bool
otherwise
= []
; Bool
show_valid_hole_fits <- GeneralFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_ShowValidHoleFits
; (SolverReportErrCtxt
ctxt, ValidHoleFits
hole_fits) <- if Bool
show_valid_hole_fits
then SolverReportErrCtxt
-> [ErrorItem] -> Hole -> TcM (SolverReportErrCtxt, ValidHoleFits)
validHoleFits SolverReportErrCtxt
ctxt [ErrorItem]
tidy_simples Hole
hole
else (SolverReportErrCtxt, ValidHoleFits)
-> TcM (SolverReportErrCtxt, ValidHoleFits)
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
ctxt, ValidHoleFits
noValidHoleFits)
; ([(SkolemInfoAnon, [TyCoVar])]
grouped_skvs, [TyCoVar]
other_tvs) <- TcType -> TcM ([(SkolemInfoAnon, [TyCoVar])], [TyCoVar])
zonkAndGroupSkolTvs TcType
hole_ty
; let reason :: DiagnosticReason
reason | ExprHole HoleExprRef
_ <- HoleSort
sort = SolverReportErrCtxt -> DiagnosticReason
cec_expr_holes SolverReportErrCtxt
ctxt
| Bool
otherwise = SolverReportErrCtxt -> DiagnosticReason
cec_type_holes SolverReportErrCtxt
ctxt
errs :: [SolverReportWithCtxt]
errs = [SolverReportErrCtxt -> TcSolverReportMsg -> SolverReportWithCtxt
SolverReportWithCtxt SolverReportErrCtxt
ctxt (TcSolverReportMsg -> SolverReportWithCtxt)
-> TcSolverReportMsg -> SolverReportWithCtxt
forall a b. (a -> b) -> a -> b
$ Hole -> HoleError -> TcSolverReportMsg
ReportHoleError Hole
hole (HoleError -> TcSolverReportMsg) -> HoleError -> TcSolverReportMsg
forall a b. (a -> b) -> a -> b
$ HoleSort -> [TyCoVar] -> [(SkolemInfoAnon, [TyCoVar])] -> HoleError
HoleError HoleSort
sort [TyCoVar]
other_tvs [(SkolemInfoAnon, [TyCoVar])]
grouped_skvs]
supp :: [SolverReportSupplementary]
supp = [ RelevantBindings -> SolverReportSupplementary
SupplementaryBindings RelevantBindings
rel_binds
, [(TcType, RealSrcSpan)] -> SolverReportSupplementary
SupplementaryCts [(TcType, RealSrcSpan)]
relevant_cts
, ValidHoleFits -> SolverReportSupplementary
SupplementaryHoleFits ValidHoleFits
hole_fits ]
; SolverReportErrCtxt -> Hole -> SolverReport -> TcM ()
maybeAddDeferredBindings SolverReportErrCtxt
ctxt Hole
hole ([SolverReportWithCtxt]
-> [SolverReportSupplementary] -> [GhcHint] -> SolverReport
SolverReport [SolverReportWithCtxt]
errs [SolverReportSupplementary]
supp [])
; TcLclEnv
-> TcRnMessage
-> Maybe SolverReportErrCtxt
-> [SolverReportSupplementary]
-> TcM (MsgEnvelope TcRnMessage)
mkErrorReport TcLclEnv
lcl_env ([SolverReportWithCtxt]
-> DiagnosticReason -> [GhcHint] -> TcRnMessage
TcRnSolverReport [SolverReportWithCtxt]
errs DiagnosticReason
reason [GhcHint]
noHints) (SolverReportErrCtxt -> Maybe SolverReportErrCtxt
forall a. a -> Maybe a
Just SolverReportErrCtxt
ctxt) [SolverReportSupplementary]
supp
}
where
lcl_env :: TcLclEnv
lcl_env = CtLoc -> TcLclEnv
ctLocEnv CtLoc
ct_loc
zonkAndGroupSkolTvs :: Type -> TcM ([(SkolemInfoAnon, [TcTyVar])], [TcTyVar])
zonkAndGroupSkolTvs :: TcType -> TcM ([(SkolemInfoAnon, [TyCoVar])], [TyCoVar])
zonkAndGroupSkolTvs TcType
hole_ty = do
[(SkolemInfoAnon, [TyCoVar])]
zonked_info <- ((SkolemInfo, [(TyCoVar, Int)])
-> IOEnv (Env TcGblEnv TcLclEnv) (SkolemInfoAnon, [TyCoVar]))
-> [(SkolemInfo, [(TyCoVar, Int)])]
-> IOEnv (Env TcGblEnv TcLclEnv) [(SkolemInfoAnon, [TyCoVar])]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(SkolemInfo
sk, [(TyCoVar, Int)]
tv) -> (,) (SkolemInfoAnon -> [TyCoVar] -> (SkolemInfoAnon, [TyCoVar]))
-> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfoAnon
-> IOEnv
(Env TcGblEnv TcLclEnv) ([TyCoVar] -> (SkolemInfoAnon, [TyCoVar]))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfoAnon
zonkSkolemInfoAnon (SkolemInfoAnon -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfoAnon)
-> (SkolemInfo -> SkolemInfoAnon)
-> SkolemInfo
-> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfoAnon
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SkolemInfo -> SkolemInfoAnon
getSkolemInfo (SkolemInfo -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfoAnon)
-> SkolemInfo -> IOEnv (Env TcGblEnv TcLclEnv) SkolemInfoAnon
forall a b. (a -> b) -> a -> b
$ SkolemInfo
sk) IOEnv
(Env TcGblEnv TcLclEnv) ([TyCoVar] -> (SkolemInfoAnon, [TyCoVar]))
-> IOEnv (Env TcGblEnv TcLclEnv) [TyCoVar]
-> IOEnv (Env TcGblEnv TcLclEnv) (SkolemInfoAnon, [TyCoVar])
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [TyCoVar] -> IOEnv (Env TcGblEnv TcLclEnv) [TyCoVar]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((TyCoVar, Int) -> TyCoVar
forall a b. (a, b) -> a
fst ((TyCoVar, Int) -> TyCoVar) -> [(TyCoVar, Int)] -> [TyCoVar]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(TyCoVar, Int)]
tv)) [(SkolemInfo, [(TyCoVar, Int)])]
skolem_list
([(SkolemInfoAnon, [TyCoVar])], [TyCoVar])
-> TcM ([(SkolemInfoAnon, [TyCoVar])], [TyCoVar])
forall (m :: * -> *) a. Monad m => a -> m a
return ([(SkolemInfoAnon, [TyCoVar])]
zonked_info, [TyCoVar]
other_tvs)
where
tvs :: [TyCoVar]
tvs = TcType -> [TyCoVar]
tyCoVarsOfTypeList TcType
hole_ty
([TyCoVar]
skol_tvs, [TyCoVar]
other_tvs) = (TyCoVar -> Bool) -> [TyCoVar] -> ([TyCoVar], [TyCoVar])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (\TyCoVar
tv -> TyCoVar -> Bool
isTcTyVar TyCoVar
tv Bool -> Bool -> Bool
&& TyCoVar -> Bool
isSkolemTyVar TyCoVar
tv) [TyCoVar]
tvs
group_skolems :: UM.UniqMap SkolemInfo ([(TcTyVar, Int)])
group_skolems :: UniqMap SkolemInfo [(TyCoVar, Int)]
group_skolems = Bag (TyCoVar, Int) -> [(TyCoVar, Int)]
forall a. Bag a -> [a]
bagToList (Bag (TyCoVar, Int) -> [(TyCoVar, Int)])
-> UniqMap SkolemInfo (Bag (TyCoVar, Int))
-> UniqMap SkolemInfo [(TyCoVar, Int)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Bag (TyCoVar, Int) -> Bag (TyCoVar, Int) -> Bag (TyCoVar, Int))
-> [(SkolemInfo, Bag (TyCoVar, Int))]
-> UniqMap SkolemInfo (Bag (TyCoVar, Int))
forall k a. Uniquable k => (a -> a -> a) -> [(k, a)] -> UniqMap k a
UM.listToUniqMap_C Bag (TyCoVar, Int) -> Bag (TyCoVar, Int) -> Bag (TyCoVar, Int)
forall a. Bag a -> Bag a -> Bag a
unionBags [(TyCoVar -> SkolemInfo
skolemSkolInfo TyCoVar
tv, (TyCoVar, Int) -> Bag (TyCoVar, Int)
forall a. a -> Bag a
unitBag (TyCoVar
tv, Int
n)) | TyCoVar
tv <- [TyCoVar]
skol_tvs | Int
n <- [Int
0..]]
skolem_list :: [(SkolemInfo, [(TyCoVar, Int)])]
skolem_list = ((SkolemInfo, [(TyCoVar, Int)])
-> (SkolemInfo, [(TyCoVar, Int)]) -> Ordering)
-> [(SkolemInfo, [(TyCoVar, Int)])]
-> [(SkolemInfo, [(TyCoVar, Int)])]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((SkolemInfo, [(TyCoVar, Int)]) -> [Int])
-> (SkolemInfo, [(TyCoVar, Int)])
-> (SkolemInfo, [(TyCoVar, Int)])
-> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing ([Int] -> [Int]
forall a. Ord a => [a] -> [a]
sort ([Int] -> [Int])
-> ((SkolemInfo, [(TyCoVar, Int)]) -> [Int])
-> (SkolemInfo, [(TyCoVar, Int)])
-> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((TyCoVar, Int) -> Int) -> [(TyCoVar, Int)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (TyCoVar, Int) -> Int
forall a b. (a, b) -> b
snd ([(TyCoVar, Int)] -> [Int])
-> ((SkolemInfo, [(TyCoVar, Int)]) -> [(TyCoVar, Int)])
-> (SkolemInfo, [(TyCoVar, Int)])
-> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SkolemInfo, [(TyCoVar, Int)]) -> [(TyCoVar, Int)]
forall a b. (a, b) -> b
snd)) (UniqMap SkolemInfo [(TyCoVar, Int)]
-> [(SkolemInfo, [(TyCoVar, Int)])]
forall k a. UniqMap k a -> [(k, a)]
UM.nonDetEltsUniqMap UniqMap SkolemInfo [(TyCoVar, Int)]
group_skolems)
maybeAddDeferredBindings :: SolverReportErrCtxt
-> Hole
-> SolverReport
-> TcM ()
maybeAddDeferredBindings :: SolverReportErrCtxt -> Hole -> SolverReport -> TcM ()
maybeAddDeferredBindings SolverReportErrCtxt
ctxt Hole
hole SolverReport
report = do
case Hole -> HoleSort
hole_sort Hole
hole of
ExprHole (HER IORef EvTerm
ref TcType
ref_ty Unique
_) -> do
Bool -> TcM () -> TcM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (SolverReportErrCtxt -> Bool
deferringAnyBindings SolverReportErrCtxt
ctxt) (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$ do
EvTerm
err_tm <- SolverReportErrCtxt
-> CtLoc -> TcType -> SolverReport -> TcM EvTerm
mkErrorTerm SolverReportErrCtxt
ctxt (Hole -> CtLoc
hole_loc Hole
hole) TcType
ref_ty SolverReport
report
IORef EvTerm -> EvTerm -> TcM ()
forall a env. IORef a -> a -> IOEnv env ()
writeMutVar IORef EvTerm
ref EvTerm
err_tm
HoleSort
_ -> () -> TcM ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
validHoleFits :: SolverReportErrCtxt
-> [ErrorItem]
-> Hole
-> TcM (SolverReportErrCtxt, ValidHoleFits)
validHoleFits :: SolverReportErrCtxt
-> [ErrorItem] -> Hole -> TcM (SolverReportErrCtxt, ValidHoleFits)
validHoleFits ctxt :: SolverReportErrCtxt
ctxt@(CEC { cec_encl :: SolverReportErrCtxt -> [Implication]
cec_encl = [Implication]
implics
, cec_tidy :: SolverReportErrCtxt -> TidyEnv
cec_tidy = TidyEnv
lcl_env}) [ErrorItem]
simps Hole
hole
= do { (TidyEnv
tidy_env, ValidHoleFits
fits) <- TidyEnv
-> [Implication]
-> [CtEvidence]
-> Hole
-> TcM (TidyEnv, ValidHoleFits)
findValidHoleFits TidyEnv
lcl_env [Implication]
implics ((ErrorItem -> CtEvidence) -> [ErrorItem] -> [CtEvidence]
forall a b. (a -> b) -> [a] -> [b]
map ErrorItem -> CtEvidence
mk_wanted [ErrorItem]
simps) Hole
hole
; (SolverReportErrCtxt, ValidHoleFits)
-> TcM (SolverReportErrCtxt, ValidHoleFits)
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
ctxt {cec_tidy :: TidyEnv
cec_tidy = TidyEnv
tidy_env}, ValidHoleFits
fits) }
where
mk_wanted :: ErrorItem -> CtEvidence
mk_wanted :: ErrorItem -> CtEvidence
mk_wanted (EI { ei_pred :: ErrorItem -> TcType
ei_pred = TcType
pred, ei_evdest :: ErrorItem -> Maybe TcEvDest
ei_evdest = Just TcEvDest
dest, ei_loc :: ErrorItem -> CtLoc
ei_loc = CtLoc
loc })
= CtWanted :: TcType -> TcEvDest -> CtLoc -> RewriterSet -> CtEvidence
CtWanted { ctev_pred :: TcType
ctev_pred = TcType
pred
, ctev_dest :: TcEvDest
ctev_dest = TcEvDest
dest
, ctev_loc :: CtLoc
ctev_loc = CtLoc
loc
, ctev_rewriters :: RewriterSet
ctev_rewriters = RewriterSet
emptyRewriterSet }
mk_wanted ErrorItem
item = String -> SDoc -> CtEvidence
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"validHoleFits no evdest" (ErrorItem -> SDoc
forall a. Outputable a => a -> SDoc
ppr ErrorItem
item)
givenConstraints :: SolverReportErrCtxt -> [(Type, RealSrcSpan)]
givenConstraints :: SolverReportErrCtxt -> [(TcType, RealSrcSpan)]
givenConstraints SolverReportErrCtxt
ctxt
= do { implic :: Implication
implic@Implic{ ic_given :: Implication -> [TyCoVar]
ic_given = [TyCoVar]
given } <- SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt
; TyCoVar
constraint <- [TyCoVar]
given
; (TcType, RealSrcSpan) -> [(TcType, RealSrcSpan)]
forall (m :: * -> *) a. Monad m => a -> m a
return (TyCoVar -> TcType
varType TyCoVar
constraint, TcLclEnv -> RealSrcSpan
tcl_loc (Implication -> TcLclEnv
ic_env Implication
implic)) }
mkIPErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkIPErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkIPErr SolverReportErrCtxt
ctxt [ErrorItem]
items
= do { (SolverReportErrCtxt
ctxt, RelevantBindings
binds_msg, ErrorItem
item1) <- Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcM (SolverReportErrCtxt, RelevantBindings, ErrorItem)
relevantBindings Bool
True SolverReportErrCtxt
ctxt ErrorItem
item1
; let msg :: SolverReport
msg = SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important SolverReportErrCtxt
ctxt (TcSolverReportMsg -> SolverReport)
-> TcSolverReportMsg -> SolverReport
forall a b. (a -> b) -> a -> b
$ NonEmpty ErrorItem -> TcSolverReportMsg
UnboundImplicitParams (ErrorItem
item1 ErrorItem -> [ErrorItem] -> NonEmpty ErrorItem
forall a. a -> [a] -> NonEmpty a
:| [ErrorItem]
others)
; SolverReport -> TcM SolverReport
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReport -> TcM SolverReport)
-> SolverReport -> TcM SolverReport
forall a b. (a -> b) -> a -> b
$ SolverReport
msg SolverReport -> SolverReport -> SolverReport
forall a. Monoid a => a -> a -> a
`mappend` RelevantBindings -> SolverReport
mk_relevant_bindings RelevantBindings
binds_msg }
where
ErrorItem
item1:[ErrorItem]
others = [ErrorItem]
items
mkFRRErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkFRRErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkFRRErr SolverReportErrCtxt
ctxt [ErrorItem]
items
= do {
; (TidyEnv
_tidy_env, [CtOrigin]
tidied_origins) <-
TidyEnv -> [CtOrigin] -> TcM (TidyEnv, [CtOrigin])
zonkTidyOrigins (SolverReportErrCtxt -> TidyEnv
cec_tidy SolverReportErrCtxt
ctxt) ((ErrorItem -> CtOrigin) -> [ErrorItem] -> [CtOrigin]
forall a b. (a -> b) -> [a] -> [b]
map ErrorItem -> CtOrigin
errorItemOrigin [ErrorItem]
items)
; let frr_infos :: [FixedRuntimeRepErrorInfo]
frr_infos =
(FixedRuntimeRepErrorInfo -> FixedRuntimeRepErrorInfo -> Ordering)
-> [FixedRuntimeRepErrorInfo] -> [FixedRuntimeRepErrorInfo]
forall a. (a -> a -> Ordering) -> [a] -> [a]
nubOrdBy (TcType -> TcType -> Ordering
nonDetCmpType (TcType -> TcType -> Ordering)
-> (FixedRuntimeRepErrorInfo -> TcType)
-> FixedRuntimeRepErrorInfo
-> FixedRuntimeRepErrorInfo
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` FixedRuntimeRepErrorInfo -> TcType
frrInfo_type) ([FixedRuntimeRepErrorInfo] -> [FixedRuntimeRepErrorInfo])
-> [FixedRuntimeRepErrorInfo] -> [FixedRuntimeRepErrorInfo]
forall a b. (a -> b) -> a -> b
$
(CtOrigin -> TcType -> FixedRuntimeRepErrorInfo)
-> [CtOrigin] -> [TcType] -> [FixedRuntimeRepErrorInfo]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith CtOrigin -> TcType -> FixedRuntimeRepErrorInfo
frr_info [CtOrigin]
tidied_origins ((ErrorItem -> TcType) -> [ErrorItem] -> [TcType]
forall a b. (a -> b) -> [a] -> [b]
map ErrorItem -> TcType
errorItemPred [ErrorItem]
items)
; SolverReport -> TcM SolverReport
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReport -> TcM SolverReport)
-> SolverReport -> TcM SolverReport
forall a b. (a -> b) -> a -> b
$ SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important SolverReportErrCtxt
ctxt (TcSolverReportMsg -> SolverReport)
-> TcSolverReportMsg -> SolverReport
forall a b. (a -> b) -> a -> b
$ [FixedRuntimeRepErrorInfo] -> TcSolverReportMsg
FixedRuntimeRepError [FixedRuntimeRepErrorInfo]
frr_infos }
where
frr_info :: CtOrigin -> PredType -> FixedRuntimeRepErrorInfo
frr_info :: CtOrigin -> TcType -> FixedRuntimeRepErrorInfo
frr_info CtOrigin
orig TcType
pty
| FixedRuntimeRepOrigin TcType
ty FRROrigin
frr_orig <- CtOrigin
orig
= FixedRuntimeRepErrorInfo :: FRROrigin -> TcType -> Bool -> FixedRuntimeRepErrorInfo
FixedRuntimeRepErrorInfo
{ frrInfo_origin :: FRROrigin
frrInfo_origin = FRROrigin
frr_orig
, frrInfo_type :: TcType
frrInfo_type = TcType
ty
, frrInfo_isReflPrim :: Bool
frrInfo_isReflPrim = Pred -> Bool
isIsReflPrimPred (TcType -> Pred
classifyPredType TcType
pty)
}
| Bool
otherwise
= String -> SDoc -> FixedRuntimeRepErrorInfo
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"mkFRRErr: not a FixedRuntimeRep origin" (SDoc -> FixedRuntimeRepErrorInfo)
-> SDoc -> FixedRuntimeRepErrorInfo
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
vcat [ String -> SDoc
text String
"origin:" SDoc -> SDoc -> SDoc
<+> CtOrigin -> SDoc
forall a. Outputable a => a -> SDoc
ppr CtOrigin
orig
, String -> SDoc
text String
"pty:" SDoc -> SDoc -> SDoc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
pty ]
mkEqErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkEqErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkEqErr SolverReportErrCtxt
ctxt [ErrorItem]
items
| ErrorItem
item:[ErrorItem]
_ <- (ErrorItem -> Bool) -> [ErrorItem] -> [ErrorItem]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (ErrorItem -> Bool) -> ErrorItem -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorItem -> Bool
ei_suppress) [ErrorItem]
items
= SolverReportErrCtxt -> ErrorItem -> TcM SolverReport
mkEqErr1 SolverReportErrCtxt
ctxt ErrorItem
item
| ErrorItem
item:[ErrorItem]
_ <- [ErrorItem]
items
= SolverReportErrCtxt -> ErrorItem -> TcM SolverReport
mkEqErr1 SolverReportErrCtxt
ctxt ErrorItem
item
| Bool
otherwise
= String -> TcM SolverReport
forall a. String -> a
panic String
"mkEqErr"
mkEqErr1 :: SolverReportErrCtxt -> ErrorItem -> TcM SolverReport
mkEqErr1 :: SolverReportErrCtxt -> ErrorItem -> TcM SolverReport
mkEqErr1 SolverReportErrCtxt
ctxt ErrorItem
item
= do { (SolverReportErrCtxt
ctxt, RelevantBindings
binds_msg, ErrorItem
item) <- Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcM (SolverReportErrCtxt, RelevantBindings, ErrorItem)
relevantBindings Bool
True SolverReportErrCtxt
ctxt ErrorItem
item
; GlobalRdrEnv
rdr_env <- TcRn GlobalRdrEnv
getGlobalRdrEnv
; FamInstEnvs
fam_envs <- TcM FamInstEnvs
tcGetFamInstEnvs
; let mb_coercible_msg :: Maybe TcSolverReportInfo
mb_coercible_msg = case ErrorItem -> EqRel
errorItemEqRel ErrorItem
item of
EqRel
NomEq -> Maybe TcSolverReportInfo
forall a. Maybe a
Nothing
EqRel
ReprEq -> CoercibleMsg -> TcSolverReportInfo
ReportCoercibleMsg (CoercibleMsg -> TcSolverReportInfo)
-> Maybe CoercibleMsg -> Maybe TcSolverReportInfo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GlobalRdrEnv
-> FamInstEnvs -> TcType -> TcType -> Maybe CoercibleMsg
mkCoercibleExplanation GlobalRdrEnv
rdr_env FamInstEnvs
fam_envs TcType
ty1 TcType
ty2
; String -> SDoc -> TcM ()
traceTc String
"mkEqErr1" (ErrorItem -> SDoc
forall a. Outputable a => a -> SDoc
ppr ErrorItem
item SDoc -> SDoc -> SDoc
$$ CtOrigin -> SDoc
pprCtOrigin (ErrorItem -> CtOrigin
errorItemOrigin ErrorItem
item))
; (TcSolverReportMsg
last_msg :| [TcSolverReportMsg]
prev_msgs, [GhcHint]
hints) <- SolverReportErrCtxt
-> ErrorItem -> TcType -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkEqErr_help SolverReportErrCtxt
ctxt ErrorItem
item TcType
ty1 TcType
ty2
; let
report :: SolverReport
report = (TcSolverReportMsg -> SolverReport)
-> [TcSolverReportMsg] -> SolverReport
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important SolverReportErrCtxt
ctxt) ([TcSolverReportMsg] -> [TcSolverReportMsg]
forall a. [a] -> [a]
reverse [TcSolverReportMsg]
prev_msgs)
SolverReport -> SolverReport -> SolverReport
forall a. Monoid a => a -> a -> a
`mappend` (SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important SolverReportErrCtxt
ctxt (TcSolverReportMsg -> SolverReport)
-> TcSolverReportMsg -> SolverReport
forall a b. (a -> b) -> a -> b
$ TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo TcSolverReportMsg
last_msg ([TcSolverReportInfo] -> TcSolverReportMsg)
-> [TcSolverReportInfo] -> TcSolverReportMsg
forall a b. (a -> b) -> a -> b
$ Maybe TcSolverReportInfo -> [TcSolverReportInfo]
forall a. Maybe a -> [a]
maybeToList Maybe TcSolverReportInfo
mb_coercible_msg)
SolverReport -> SolverReport -> SolverReport
forall a. Monoid a => a -> a -> a
`mappend` (RelevantBindings -> SolverReport
mk_relevant_bindings RelevantBindings
binds_msg)
SolverReport -> SolverReport -> SolverReport
forall a. Monoid a => a -> a -> a
`mappend` ([GhcHint] -> SolverReport
mk_report_hints [GhcHint]
hints)
; SolverReport -> TcM SolverReport
forall (m :: * -> *) a. Monad m => a -> m a
return SolverReport
report }
where
(TcType
ty1, TcType
ty2) = TcType -> (TcType, TcType)
getEqPredTys (ErrorItem -> TcType
errorItemPred ErrorItem
item)
mkCoercibleExplanation :: GlobalRdrEnv -> FamInstEnvs
-> TcType -> TcType -> Maybe CoercibleMsg
mkCoercibleExplanation :: GlobalRdrEnv
-> FamInstEnvs -> TcType -> TcType -> Maybe CoercibleMsg
mkCoercibleExplanation GlobalRdrEnv
rdr_env FamInstEnvs
fam_envs TcType
ty1 TcType
ty2
| Just (TyCon
tc, [TcType]
tys) <- HasCallStack => TcType -> Maybe (TyCon, [TcType])
TcType -> Maybe (TyCon, [TcType])
tcSplitTyConApp_maybe TcType
ty1
, (TyCon
rep_tc, [TcType]
_, Coercion
_) <- FamInstEnvs -> TyCon -> [TcType] -> (TyCon, [TcType], Coercion)
tcLookupDataFamInst FamInstEnvs
fam_envs TyCon
tc [TcType]
tys
, Just CoercibleMsg
msg <- TyCon -> Maybe CoercibleMsg
coercible_msg_for_tycon TyCon
rep_tc
= CoercibleMsg -> Maybe CoercibleMsg
forall a. a -> Maybe a
Just CoercibleMsg
msg
| Just (TyCon
tc, [TcType]
tys) <- HasDebugCallStack => TcType -> Maybe (TyCon, [TcType])
TcType -> Maybe (TyCon, [TcType])
splitTyConApp_maybe TcType
ty2
, (TyCon
rep_tc, [TcType]
_, Coercion
_) <- FamInstEnvs -> TyCon -> [TcType] -> (TyCon, [TcType], Coercion)
tcLookupDataFamInst FamInstEnvs
fam_envs TyCon
tc [TcType]
tys
, Just CoercibleMsg
msg <- TyCon -> Maybe CoercibleMsg
coercible_msg_for_tycon TyCon
rep_tc
= CoercibleMsg -> Maybe CoercibleMsg
forall a. a -> Maybe a
Just CoercibleMsg
msg
| Just (TcType
s1, TcType
_) <- TcType -> Maybe (TcType, TcType)
tcSplitAppTy_maybe TcType
ty1
, Just (TcType
s2, TcType
_) <- TcType -> Maybe (TcType, TcType)
tcSplitAppTy_maybe TcType
ty2
, TcType
s1 TcType -> TcType -> Bool
`eqType` TcType
s2
, TcType -> Bool
has_unknown_roles TcType
s1
= CoercibleMsg -> Maybe CoercibleMsg
forall a. a -> Maybe a
Just (CoercibleMsg -> Maybe CoercibleMsg)
-> CoercibleMsg -> Maybe CoercibleMsg
forall a b. (a -> b) -> a -> b
$ TcType -> CoercibleMsg
UnknownRoles TcType
s1
| Bool
otherwise
= Maybe CoercibleMsg
forall a. Maybe a
Nothing
where
coercible_msg_for_tycon :: TyCon -> Maybe CoercibleMsg
coercible_msg_for_tycon TyCon
tc
| TyCon -> Bool
isAbstractTyCon TyCon
tc
= CoercibleMsg -> Maybe CoercibleMsg
forall a. a -> Maybe a
Just (CoercibleMsg -> Maybe CoercibleMsg)
-> CoercibleMsg -> Maybe CoercibleMsg
forall a b. (a -> b) -> a -> b
$ TyCon -> CoercibleMsg
TyConIsAbstract TyCon
tc
| TyCon -> Bool
isNewTyCon TyCon
tc
, [DataCon
data_con] <- TyCon -> [DataCon]
tyConDataCons TyCon
tc
, let dc_name :: Name
dc_name = DataCon -> Name
dataConName DataCon
data_con
, Maybe GlobalRdrElt -> Bool
forall a. Maybe a -> Bool
isNothing (GlobalRdrEnv -> Name -> Maybe GlobalRdrElt
lookupGRE_Name GlobalRdrEnv
rdr_env Name
dc_name)
= CoercibleMsg -> Maybe CoercibleMsg
forall a. a -> Maybe a
Just (CoercibleMsg -> Maybe CoercibleMsg)
-> CoercibleMsg -> Maybe CoercibleMsg
forall a b. (a -> b) -> a -> b
$ TyCon -> DataCon -> CoercibleMsg
OutOfScopeNewtypeConstructor TyCon
tc DataCon
data_con
| Bool
otherwise = Maybe CoercibleMsg
forall a. Maybe a
Nothing
has_unknown_roles :: TcType -> Bool
has_unknown_roles TcType
ty
| Just (TyCon
tc, [TcType]
tys) <- HasCallStack => TcType -> Maybe (TyCon, [TcType])
TcType -> Maybe (TyCon, [TcType])
tcSplitTyConApp_maybe TcType
ty
= [TcType]
tys [TcType] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthAtLeast` TyCon -> Int
tyConArity TyCon
tc
| Just (TcType
s, TcType
_) <- TcType -> Maybe (TcType, TcType)
tcSplitAppTy_maybe TcType
ty
= TcType -> Bool
has_unknown_roles TcType
s
| TcType -> Bool
isTyVarTy TcType
ty
= Bool
True
| Bool
otherwise
= Bool
False
type AccReportMsgs = NonEmpty TcSolverReportMsg
mkEqErr_help :: SolverReportErrCtxt
-> ErrorItem
-> TcType -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkEqErr_help :: SolverReportErrCtxt
-> ErrorItem -> TcType -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkEqErr_help SolverReportErrCtxt
ctxt ErrorItem
item TcType
ty1 TcType
ty2
| Just (TyCoVar
tv1, Coercion
_) <- TcType -> Maybe (TyCoVar, Coercion)
tcGetCastedTyVar_maybe TcType
ty1
= SolverReportErrCtxt
-> ErrorItem -> TyCoVar -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkTyVarEqErr SolverReportErrCtxt
ctxt ErrorItem
item TyCoVar
tv1 TcType
ty2
| Just (TyCoVar
tv2, Coercion
_) <- TcType -> Maybe (TyCoVar, Coercion)
tcGetCastedTyVar_maybe TcType
ty2
= SolverReportErrCtxt
-> ErrorItem -> TyCoVar -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkTyVarEqErr SolverReportErrCtxt
ctxt ErrorItem
item TyCoVar
tv2 TcType
ty1
| Bool
otherwise
= (AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
-> ErrorItem -> TcType -> TcType -> TcSolverReportMsg
reportEqErr SolverReportErrCtxt
ctxt ErrorItem
item TcType
ty1 TcType
ty2 TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [], [])
reportEqErr :: SolverReportErrCtxt
-> ErrorItem
-> TcType -> TcType -> TcSolverReportMsg
reportEqErr :: SolverReportErrCtxt
-> ErrorItem -> TcType -> TcType -> TcSolverReportMsg
reportEqErr SolverReportErrCtxt
ctxt ErrorItem
item TcType
ty1 TcType
ty2
= TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo TcSolverReportMsg
mismatch [TcSolverReportInfo]
eqInfos
where
mismatch :: TcSolverReportMsg
mismatch = Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcType
-> TcType
-> TcSolverReportMsg
misMatchOrCND Bool
False SolverReportErrCtxt
ctxt ErrorItem
item TcType
ty1 TcType
ty2
eqInfos :: [TcSolverReportInfo]
eqInfos = TcType -> TcType -> [TcSolverReportInfo]
eqInfoMsgs TcType
ty1 TcType
ty2
mkTyVarEqErr :: SolverReportErrCtxt -> ErrorItem
-> TcTyVar -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkTyVarEqErr :: SolverReportErrCtxt
-> ErrorItem -> TyCoVar -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkTyVarEqErr SolverReportErrCtxt
ctxt ErrorItem
item TyCoVar
tv1 TcType
ty2
= do { String -> SDoc -> TcM ()
traceTc String
"mkTyVarEqErr" (ErrorItem -> SDoc
forall a. Outputable a => a -> SDoc
ppr ErrorItem
item SDoc -> SDoc -> SDoc
$$ TyCoVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVar
tv1 SDoc -> SDoc -> SDoc
$$ TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
ty2)
; SolverReportErrCtxt
-> ErrorItem -> TyCoVar -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkTyVarEqErr' SolverReportErrCtxt
ctxt ErrorItem
item TyCoVar
tv1 TcType
ty2 }
mkTyVarEqErr' :: SolverReportErrCtxt -> ErrorItem
-> TcTyVar -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkTyVarEqErr' :: SolverReportErrCtxt
-> ErrorItem -> TyCoVar -> TcType -> TcM (AccReportMsgs, [GhcHint])
mkTyVarEqErr' SolverReportErrCtxt
ctxt ErrorItem
item TyCoVar
tv1 TcType
ty2
| CheckTyEqResult
check_eq_result CheckTyEqResult -> CheckTyEqProblem -> Bool
`cterHasProblem` CheckTyEqProblem
cteImpredicative = do
[TcSolverReportInfo]
tyvar_eq_info <- TyCoVar -> TcType -> TcM [TcSolverReportInfo]
extraTyVarEqInfo TyCoVar
tv1 TcType
ty2
let
poly_msg :: TcSolverReportMsg
poly_msg = ErrorItem -> TyCoVar -> TcType -> TcSolverReportMsg
CannotUnifyWithPolytype ErrorItem
item TyCoVar
tv1 TcType
ty2
poly_msg_with_info :: TcSolverReportMsg
poly_msg_with_info
| TyCoVar -> Bool
isSkolemTyVar TyCoVar
tv1
= TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo TcSolverReportMsg
poly_msg [TcSolverReportInfo]
tyvar_eq_info
| Bool
otherwise
= TcSolverReportMsg
poly_msg
(AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportMsg
poly_msg_with_info TcSolverReportMsg -> AccReportMsgs -> AccReportMsgs
forall a. a -> NonEmpty a -> NonEmpty a
<| TcSolverReportMsg
headline_msg TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [], [])
| TyCoVar -> Bool
isSkolemTyVar TyCoVar
tv1
Bool -> Bool -> Bool
|| TyCoVar -> Bool
isTyVarTyVar TyCoVar
tv1 Bool -> Bool -> Bool
&& Bool -> Bool
not (TcType -> Bool
isTyVarTy TcType
ty2)
Bool -> Bool -> Bool
|| ErrorItem -> EqRel
errorItemEqRel ErrorItem
item EqRel -> EqRel -> Bool
forall a. Eq a => a -> a -> Bool
== EqRel
ReprEq
= do
[TcSolverReportInfo]
tv_extra <- TyCoVar -> TcType -> TcM [TcSolverReportInfo]
extraTyVarEqInfo TyCoVar
tv1 TcType
ty2
(AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo TcSolverReportMsg
headline_msg [TcSolverReportInfo]
tv_extra TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [], [GhcHint]
add_sig)
| CheckTyEqResult -> Bool
cterHasOccursCheck CheckTyEqResult
check_eq_result
= let extras2 :: [TcSolverReportInfo]
extras2 = TcType -> TcType -> [TcSolverReportInfo]
eqInfoMsgs TcType
ty1 TcType
ty2
interesting_tyvars :: [TyCoVar]
interesting_tyvars = (TyCoVar -> Bool) -> [TyCoVar] -> [TyCoVar]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (TyCoVar -> Bool) -> TyCoVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TcType -> Bool
noFreeVarsOfType (TcType -> Bool) -> (TyCoVar -> TcType) -> TyCoVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCoVar -> TcType
tyVarKind) ([TyCoVar] -> [TyCoVar]) -> [TyCoVar] -> [TyCoVar]
forall a b. (a -> b) -> a -> b
$
(TyCoVar -> Bool) -> [TyCoVar] -> [TyCoVar]
forall a. (a -> Bool) -> [a] -> [a]
filter TyCoVar -> Bool
isTyVar ([TyCoVar] -> [TyCoVar]) -> [TyCoVar] -> [TyCoVar]
forall a b. (a -> b) -> a -> b
$
FV -> [TyCoVar]
fvVarList (FV -> [TyCoVar]) -> FV -> [TyCoVar]
forall a b. (a -> b) -> a -> b
$
TcType -> FV
tyCoFVsOfType TcType
ty1 FV -> FV -> FV
`unionFV` TcType -> FV
tyCoFVsOfType TcType
ty2
extras3 :: [TcSolverReportInfo]
extras3 = case [TyCoVar]
interesting_tyvars of
[] -> []
(TyCoVar
tv : [TyCoVar]
tvs) -> [NonEmpty TyCoVar -> TcSolverReportInfo
OccursCheckInterestingTyVars (TyCoVar
tv TyCoVar -> [TyCoVar] -> NonEmpty TyCoVar
forall a. a -> [a] -> NonEmpty a
:| [TyCoVar]
tvs)]
in (AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo TcSolverReportMsg
headline_msg ([TcSolverReportInfo]
extras2 [TcSolverReportInfo]
-> [TcSolverReportInfo] -> [TcSolverReportInfo]
forall a. [a] -> [a] -> [a]
++ [TcSolverReportInfo]
extras3) TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [], [])
| TcType -> Bool
hasCoercionHoleTy TcType
ty2
= (AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (ErrorItem -> TcSolverReportMsg
mkBlockedEqErr ErrorItem
item TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [], [])
| (Implication
implic:[Implication]
_) <- SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt
, Implic { ic_skols :: Implication -> [TyCoVar]
ic_skols = [TyCoVar]
skols } <- Implication
implic
, TyCoVar
tv1 TyCoVar -> [TyCoVar] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [TyCoVar]
skols
= do
[TcSolverReportInfo]
tv_extra <- TyCoVar -> TcType -> TcM [TcSolverReportInfo]
extraTyVarEqInfo TyCoVar
tv1 TcType
ty2
(AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo TcSolverReportMsg
mismatch_msg [TcSolverReportInfo]
tv_extra TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [], [])
| (Implication
implic:[Implication]
_) <- SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt
, Implic { ic_skols :: Implication -> [TyCoVar]
ic_skols = [TyCoVar]
skols } <- Implication
implic
, let esc_skols :: [TyCoVar]
esc_skols = (TyCoVar -> Bool) -> [TyCoVar] -> [TyCoVar]
forall a. (a -> Bool) -> [a] -> [a]
filter (TyCoVar -> TyCoVarSet -> Bool
`elemVarSet` (TcType -> TyCoVarSet
tyCoVarsOfType TcType
ty2)) [TyCoVar]
skols
, Bool -> Bool
not ([TyCoVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TyCoVar]
esc_skols)
= (AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (ErrorItem -> Implication -> [TyCoVar] -> TcSolverReportMsg
SkolemEscape ErrorItem
item Implication
implic [TyCoVar]
esc_skols TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [TcSolverReportMsg
mismatch_msg], [])
| (Implication
implic:[Implication]
_) <- SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt
, Implic { ic_tclvl :: Implication -> TcLevel
ic_tclvl = TcLevel
lvl } <- Implication
implic
= Bool
-> SDoc
-> TcM (AccReportMsgs, [GhcHint])
-> TcM (AccReportMsgs, [GhcHint])
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Bool -> Bool
not (TcLevel -> TyCoVar -> Bool
isTouchableMetaTyVar TcLevel
lvl TyCoVar
tv1))
(TyCoVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVar
tv1 SDoc -> SDoc -> SDoc
$$ TcLevel -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcLevel
lvl) (TcM (AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint]))
-> TcM (AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall a b. (a -> b) -> a -> b
$ do
let tclvl_extra :: TcSolverReportMsg
tclvl_extra = TyCoVar -> Implication -> TcSolverReportMsg
UntouchableVariable TyCoVar
tv1 Implication
implic
[TcSolverReportInfo]
tv_extra <- TyCoVar -> TcType -> TcM [TcSolverReportInfo]
extraTyVarEqInfo TyCoVar
tv1 TcType
ty2
(AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo TcSolverReportMsg
tclvl_extra [TcSolverReportInfo]
tv_extra TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [TcSolverReportMsg
mismatch_msg], [GhcHint]
add_sig)
| Bool
otherwise
= (AccReportMsgs, [GhcHint]) -> TcM (AccReportMsgs, [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
-> ErrorItem -> TcType -> TcType -> TcSolverReportMsg
reportEqErr SolverReportErrCtxt
ctxt ErrorItem
item (TyCoVar -> TcType
mkTyVarTy TyCoVar
tv1) TcType
ty2 TcSolverReportMsg -> [TcSolverReportMsg] -> AccReportMsgs
forall a. a -> [a] -> NonEmpty a
:| [], [])
where
headline_msg :: TcSolverReportMsg
headline_msg = Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcType
-> TcType
-> TcSolverReportMsg
misMatchOrCND Bool
insoluble_occurs_check SolverReportErrCtxt
ctxt ErrorItem
item TcType
ty1 TcType
ty2
mismatch_msg :: TcSolverReportMsg
mismatch_msg = ErrorItem -> TcType -> TcType -> TcSolverReportMsg
mkMismatchMsg ErrorItem
item TcType
ty1 TcType
ty2
add_sig :: [GhcHint]
add_sig = Maybe GhcHint -> [GhcHint]
forall a. Maybe a -> [a]
maybeToList (Maybe GhcHint -> [GhcHint]) -> Maybe GhcHint -> [GhcHint]
forall a b. (a -> b) -> a -> b
$ SolverReportErrCtxt -> TcType -> TcType -> Maybe GhcHint
suggestAddSig SolverReportErrCtxt
ctxt TcType
ty1 TcType
ty2
ty1 :: TcType
ty1 = TyCoVar -> TcType
mkTyVarTy TyCoVar
tv1
check_eq_result :: CheckTyEqResult
check_eq_result = case ErrorItem -> Maybe CtIrredReason
ei_m_reason ErrorItem
item of
Just (NonCanonicalReason CheckTyEqResult
result) -> CheckTyEqResult
result
Maybe CtIrredReason
_ -> TyCoVar -> TcType -> CheckTyEqResult
checkTyVarEq TyCoVar
tv1 TcType
ty2
insoluble_occurs_check :: Bool
insoluble_occurs_check = CheckTyEqResult
check_eq_result CheckTyEqResult -> CheckTyEqProblem -> Bool
`cterHasProblem` CheckTyEqProblem
cteInsolubleOccurs
eqInfoMsgs :: TcType -> TcType -> [TcSolverReportInfo]
eqInfoMsgs :: TcType -> TcType -> [TcSolverReportInfo]
eqInfoMsgs TcType
ty1 TcType
ty2
= [Maybe TcSolverReportInfo] -> [TcSolverReportInfo]
forall a. [Maybe a] -> [a]
catMaybes [Maybe TcSolverReportInfo
tyfun_msg, Maybe TcSolverReportInfo
ambig_msg]
where
mb_fun1 :: Maybe TyCon
mb_fun1 = TcType -> Maybe TyCon
isTyFun_maybe TcType
ty1
mb_fun2 :: Maybe TyCon
mb_fun2 = TcType -> Maybe TyCon
isTyFun_maybe TcType
ty2
ambig_tkvs1 :: ([TyCoVar], [TyCoVar])
ambig_tkvs1 = ([TyCoVar], [TyCoVar])
-> (TyCon -> ([TyCoVar], [TyCoVar]))
-> Maybe TyCon
-> ([TyCoVar], [TyCoVar])
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([TyCoVar], [TyCoVar])
forall a. Monoid a => a
mempty (\TyCon
_ -> TcType -> ([TyCoVar], [TyCoVar])
ambigTkvsOfTy TcType
ty1) Maybe TyCon
mb_fun1
ambig_tkvs2 :: ([TyCoVar], [TyCoVar])
ambig_tkvs2 = ([TyCoVar], [TyCoVar])
-> (TyCon -> ([TyCoVar], [TyCoVar]))
-> Maybe TyCon
-> ([TyCoVar], [TyCoVar])
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([TyCoVar], [TyCoVar])
forall a. Monoid a => a
mempty (\TyCon
_ -> TcType -> ([TyCoVar], [TyCoVar])
ambigTkvsOfTy TcType
ty2) Maybe TyCon
mb_fun2
ambig_tkvs :: ([TyCoVar], [TyCoVar])
ambig_tkvs@([TyCoVar]
ambig_kvs, [TyCoVar]
ambig_tvs) = ([TyCoVar], [TyCoVar])
ambig_tkvs1 ([TyCoVar], [TyCoVar])
-> ([TyCoVar], [TyCoVar]) -> ([TyCoVar], [TyCoVar])
forall a. Semigroup a => a -> a -> a
S.<> ([TyCoVar], [TyCoVar])
ambig_tkvs2
ambig_msg :: Maybe TcSolverReportInfo
ambig_msg | Maybe TyCon -> Bool
forall a. Maybe a -> Bool
isJust Maybe TyCon
mb_fun1 Bool -> Bool -> Bool
|| Maybe TyCon -> Bool
forall a. Maybe a -> Bool
isJust Maybe TyCon
mb_fun2
, Bool -> Bool
not ([TyCoVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TyCoVar]
ambig_kvs Bool -> Bool -> Bool
&& [TyCoVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TyCoVar]
ambig_tvs)
= TcSolverReportInfo -> Maybe TcSolverReportInfo
forall a. a -> Maybe a
Just (TcSolverReportInfo -> Maybe TcSolverReportInfo)
-> TcSolverReportInfo -> Maybe TcSolverReportInfo
forall a b. (a -> b) -> a -> b
$ Bool -> ([TyCoVar], [TyCoVar]) -> TcSolverReportInfo
Ambiguity Bool
False ([TyCoVar], [TyCoVar])
ambig_tkvs
| Bool
otherwise
= Maybe TcSolverReportInfo
forall a. Maybe a
Nothing
tyfun_msg :: Maybe TcSolverReportInfo
tyfun_msg | Just TyCon
tc1 <- Maybe TyCon
mb_fun1
, Just TyCon
tc2 <- Maybe TyCon
mb_fun2
, TyCon
tc1 TyCon -> TyCon -> Bool
forall a. Eq a => a -> a -> Bool
== TyCon
tc2
, Bool -> Bool
not (TyCon -> Role -> Bool
isInjectiveTyCon TyCon
tc1 Role
Nominal)
= TcSolverReportInfo -> Maybe TcSolverReportInfo
forall a. a -> Maybe a
Just (TcSolverReportInfo -> Maybe TcSolverReportInfo)
-> TcSolverReportInfo -> Maybe TcSolverReportInfo
forall a b. (a -> b) -> a -> b
$ TyCon -> TcSolverReportInfo
NonInjectiveTyFam TyCon
tc1
| Bool
otherwise
= Maybe TcSolverReportInfo
forall a. Maybe a
Nothing
misMatchOrCND :: Bool -> SolverReportErrCtxt -> ErrorItem
-> TcType -> TcType -> TcSolverReportMsg
misMatchOrCND :: Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcType
-> TcType
-> TcSolverReportMsg
misMatchOrCND Bool
insoluble_occurs_check SolverReportErrCtxt
ctxt ErrorItem
item TcType
ty1 TcType
ty2
| Bool
insoluble_occurs_check
Bool -> Bool -> Bool
|| (TcType -> Bool
isRigidTy TcType
ty1 Bool -> Bool -> Bool
&& TcType -> Bool
isRigidTy TcType
ty2)
Bool -> Bool -> Bool
|| (ErrorItem -> CtFlavour
ei_flavour ErrorItem
item CtFlavour -> CtFlavour -> Bool
forall a. Eq a => a -> a -> Bool
== CtFlavour
Given)
Bool -> Bool -> Bool
|| [Implication] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Implication]
givens
=
ErrorItem -> TcType -> TcType -> TcSolverReportMsg
mkMismatchMsg ErrorItem
item TcType
ty1 TcType
ty2
| Bool
otherwise
= [Implication]
-> NonEmpty ErrorItem -> Maybe CND_Extra -> TcSolverReportMsg
CouldNotDeduce [Implication]
givens (ErrorItem
item ErrorItem -> [ErrorItem] -> NonEmpty ErrorItem
forall a. a -> [a] -> NonEmpty a
:| []) (CND_Extra -> Maybe CND_Extra
forall a. a -> Maybe a
Just (CND_Extra -> Maybe CND_Extra) -> CND_Extra -> Maybe CND_Extra
forall a b. (a -> b) -> a -> b
$ TypeOrKind -> TcType -> TcType -> CND_Extra
CND_Extra TypeOrKind
level TcType
ty1 TcType
ty2)
where
level :: TypeOrKind
level = CtLoc -> Maybe TypeOrKind
ctLocTypeOrKind_maybe (ErrorItem -> CtLoc
errorItemCtLoc ErrorItem
item) Maybe TypeOrKind -> TypeOrKind -> TypeOrKind
forall a. Maybe a -> a -> a
`orElse` TypeOrKind
TypeLevel
givens :: [Implication]
givens = [ Implication
given | Implication
given <- SolverReportErrCtxt -> [Implication]
getUserGivens SolverReportErrCtxt
ctxt, Implication -> HasGivenEqs
ic_given_eqs Implication
given HasGivenEqs -> HasGivenEqs -> Bool
forall a. Eq a => a -> a -> Bool
/= HasGivenEqs
NoGivenEqs ]
mkBlockedEqErr :: ErrorItem -> TcSolverReportMsg
mkBlockedEqErr :: ErrorItem -> TcSolverReportMsg
mkBlockedEqErr ErrorItem
item = ErrorItem -> TcSolverReportMsg
BlockedEquality ErrorItem
item
extraTyVarEqInfo :: TcTyVar -> TcType -> TcM [TcSolverReportInfo]
TyCoVar
tv1 TcType
ty2
= (:) (TcSolverReportInfo
-> [TcSolverReportInfo] -> [TcSolverReportInfo])
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
-> IOEnv
(Env TcGblEnv TcLclEnv)
([TcSolverReportInfo] -> [TcSolverReportInfo])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyCoVar -> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
extraTyVarInfo TyCoVar
tv1 IOEnv
(Env TcGblEnv TcLclEnv)
([TcSolverReportInfo] -> [TcSolverReportInfo])
-> TcM [TcSolverReportInfo] -> TcM [TcSolverReportInfo]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TcType -> TcM [TcSolverReportInfo]
ty_extra TcType
ty2
where
ty_extra :: TcType -> TcM [TcSolverReportInfo]
ty_extra TcType
ty = case TcType -> Maybe (TyCoVar, Coercion)
tcGetCastedTyVar_maybe TcType
ty of
Just (TyCoVar
tv, Coercion
_) -> (TcSolverReportInfo -> [TcSolverReportInfo] -> [TcSolverReportInfo]
forall a. a -> [a] -> [a]
:[]) (TcSolverReportInfo -> [TcSolverReportInfo])
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
-> TcM [TcSolverReportInfo]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TyCoVar -> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
extraTyVarInfo TyCoVar
tv
Maybe (TyCoVar, Coercion)
Nothing -> [TcSolverReportInfo] -> TcM [TcSolverReportInfo]
forall (m :: * -> *) a. Monad m => a -> m a
return []
extraTyVarInfo :: TcTyVar -> TcM TcSolverReportInfo
TyCoVar
tv = Bool
-> SDoc
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (TyCoVar -> Bool
isTyVar TyCoVar
tv) (TyCoVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVar
tv) (IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo)
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
forall a b. (a -> b) -> a -> b
$
case TyCoVar -> TcTyVarDetails
tcTyVarDetails TyCoVar
tv of
SkolemTv SkolemInfo
skol_info TcLevel
lvl Bool
overlaps -> do
SkolemInfo
new_skol_info <- SkolemInfo -> TcM SkolemInfo
zonkSkolemInfo SkolemInfo
skol_info
TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo)
-> TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
forall a b. (a -> b) -> a -> b
$ TyCoVar -> TcSolverReportInfo
TyVarInfo (Name -> TcType -> TcTyVarDetails -> TyCoVar
mkTcTyVar (TyCoVar -> Name
tyVarName TyCoVar
tv) (TyCoVar -> TcType
tyVarKind TyCoVar
tv) (SkolemInfo -> TcLevel -> Bool -> TcTyVarDetails
SkolemTv SkolemInfo
new_skol_info TcLevel
lvl Bool
overlaps))
TcTyVarDetails
_ -> TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo)
-> TcSolverReportInfo
-> IOEnv (Env TcGblEnv TcLclEnv) TcSolverReportInfo
forall a b. (a -> b) -> a -> b
$ TyCoVar -> TcSolverReportInfo
TyVarInfo TyCoVar
tv
suggestAddSig :: SolverReportErrCtxt -> TcType -> TcType -> Maybe GhcHint
suggestAddSig :: SolverReportErrCtxt -> TcType -> TcType -> Maybe GhcHint
suggestAddSig SolverReportErrCtxt
ctxt TcType
ty1 TcType
_ty2
| Name
bndr : [Name]
bndrs <- [Name]
inferred_bndrs
= GhcHint -> Maybe GhcHint
forall a. a -> Maybe a
Just (GhcHint -> Maybe GhcHint) -> GhcHint -> Maybe GhcHint
forall a b. (a -> b) -> a -> b
$ AvailableBindings -> GhcHint
SuggestAddTypeSignatures (AvailableBindings -> GhcHint) -> AvailableBindings -> GhcHint
forall a b. (a -> b) -> a -> b
$ NonEmpty Name -> AvailableBindings
NamedBindings (Name
bndr Name -> [Name] -> NonEmpty Name
forall a. a -> [a] -> NonEmpty a
:| [Name]
bndrs)
| Bool
otherwise
= Maybe GhcHint
forall a. Maybe a
Nothing
where
inferred_bndrs :: [Name]
inferred_bndrs =
case TcType -> Maybe TyCoVar
tcGetTyVar_maybe TcType
ty1 of
Just TyCoVar
tv | TyCoVar -> Bool
isSkolemTyVar TyCoVar
tv -> [Implication] -> Bool -> TyCoVar -> [Name]
find (SolverReportErrCtxt -> [Implication]
cec_encl SolverReportErrCtxt
ctxt) Bool
False TyCoVar
tv
Maybe TyCoVar
_ -> []
find :: [Implication] -> Bool -> TyCoVar -> [Name]
find [] Bool
_ TyCoVar
_ = []
find (Implication
implic:[Implication]
implics) Bool
seen_eqs TyCoVar
tv
| TyCoVar
tv TyCoVar -> [TyCoVar] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Implication -> [TyCoVar]
ic_skols Implication
implic
, InferSkol [(Name, TcType)]
prs <- Implication -> SkolemInfoAnon
ic_info Implication
implic
, Bool
seen_eqs
= ((Name, TcType) -> Name) -> [(Name, TcType)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, TcType) -> Name
forall a b. (a, b) -> a
fst [(Name, TcType)]
prs
| Bool
otherwise
= [Implication] -> Bool -> TyCoVar -> [Name]
find [Implication]
implics (Bool
seen_eqs Bool -> Bool -> Bool
|| Implication -> HasGivenEqs
ic_given_eqs Implication
implic HasGivenEqs -> HasGivenEqs -> Bool
forall a. Eq a => a -> a -> Bool
/= HasGivenEqs
NoGivenEqs) TyCoVar
tv
mkMismatchMsg :: ErrorItem -> Type -> Type -> TcSolverReportMsg
mkMismatchMsg :: ErrorItem -> TcType -> TcType -> TcSolverReportMsg
mkMismatchMsg ErrorItem
item TcType
ty1 TcType
ty2 =
case CtOrigin
orig of
TypeEqOrigin { TcType
uo_actual :: CtOrigin -> TcType
uo_actual :: TcType
uo_actual, TcType
uo_expected :: CtOrigin -> TcType
uo_expected :: TcType
uo_expected, uo_thing :: CtOrigin -> Maybe TypedThing
uo_thing = Maybe TypedThing
mb_thing } ->
TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo
(TypeEqMismatch :: Bool
-> ErrorItem
-> TcType
-> TcType
-> TcType
-> TcType
-> Maybe TypedThing
-> TcSolverReportMsg
TypeEqMismatch
{ teq_mismatch_ppr_explicit_kinds :: Bool
teq_mismatch_ppr_explicit_kinds = Bool
ppr_explicit_kinds
, teq_mismatch_item :: ErrorItem
teq_mismatch_item = ErrorItem
item
, teq_mismatch_ty1 :: TcType
teq_mismatch_ty1 = TcType
ty1
, teq_mismatch_ty2 :: TcType
teq_mismatch_ty2 = TcType
ty2
, teq_mismatch_actual :: TcType
teq_mismatch_actual = TcType
uo_actual
, teq_mismatch_expected :: TcType
teq_mismatch_expected = TcType
uo_expected
, teq_mismatch_what :: Maybe TypedThing
teq_mismatch_what = Maybe TypedThing
mb_thing})
[TcSolverReportInfo]
extras
KindEqOrigin TcType
cty1 TcType
cty2 CtOrigin
sub_o Maybe TypeOrKind
mb_sub_t_or_k ->
TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo (Bool -> ErrorItem -> TcType -> TcType -> TcSolverReportMsg
Mismatch Bool
False ErrorItem
item TcType
ty1 TcType
ty2)
(TcType
-> TcType -> CtOrigin -> Maybe TypeOrKind -> TcSolverReportInfo
WhenMatching TcType
cty1 TcType
cty2 CtOrigin
sub_o Maybe TypeOrKind
mb_sub_t_or_k TcSolverReportInfo -> [TcSolverReportInfo] -> [TcSolverReportInfo]
forall a. a -> [a] -> [a]
: [TcSolverReportInfo]
extras)
CtOrigin
_ ->
TcSolverReportMsg -> [TcSolverReportInfo] -> TcSolverReportMsg
mkTcReportWithInfo
(Bool -> ErrorItem -> TcType -> TcType -> TcSolverReportMsg
Mismatch Bool
False ErrorItem
item TcType
ty1 TcType
ty2)
[TcSolverReportInfo]
extras
where
orig :: CtOrigin
orig = ErrorItem -> CtOrigin
errorItemOrigin ErrorItem
item
extras :: [TcSolverReportInfo]
extras = TcType -> TcType -> [TcSolverReportInfo]
sameOccExtras TcType
ty2 TcType
ty1
ppr_explicit_kinds :: Bool
ppr_explicit_kinds = TcType -> TcType -> CtOrigin -> Bool
shouldPprWithExplicitKinds TcType
ty1 TcType
ty2 CtOrigin
orig
shouldPprWithExplicitKinds :: Type -> Type -> CtOrigin -> Bool
shouldPprWithExplicitKinds :: TcType -> TcType -> CtOrigin -> Bool
shouldPprWithExplicitKinds TcType
_ty1 TcType
_ty2 (TypeEqOrigin { uo_actual :: CtOrigin -> TcType
uo_actual = TcType
act
, uo_expected :: CtOrigin -> TcType
uo_expected = TcType
exp
, uo_visible :: CtOrigin -> Bool
uo_visible = Bool
vis })
| Bool -> Bool
not Bool
vis = Bool
True
| Bool
otherwise = TcType -> TcType -> Bool
tcEqTypeVis TcType
act TcType
exp
shouldPprWithExplicitKinds TcType
ty1 TcType
ty2 CtOrigin
_ct
= TcType -> TcType -> Bool
tcEqTypeVis TcType
ty1 TcType
ty2
sameOccExtras :: TcType -> TcType -> [TcSolverReportInfo]
TcType
ty1 TcType
ty2
| Just (TyCon
tc1, [TcType]
_) <- HasCallStack => TcType -> Maybe (TyCon, [TcType])
TcType -> Maybe (TyCon, [TcType])
tcSplitTyConApp_maybe TcType
ty1
, Just (TyCon
tc2, [TcType]
_) <- HasCallStack => TcType -> Maybe (TyCon, [TcType])
TcType -> Maybe (TyCon, [TcType])
tcSplitTyConApp_maybe TcType
ty2
, let n1 :: Name
n1 = TyCon -> Name
tyConName TyCon
tc1
n2 :: Name
n2 = TyCon -> Name
tyConName TyCon
tc2
same_occ :: Bool
same_occ = Name -> OccName
nameOccName Name
n1 OccName -> OccName -> Bool
forall a. Eq a => a -> a -> Bool
== Name -> OccName
nameOccName Name
n2
same_pkg :: Bool
same_pkg = Module -> Unit
forall unit. GenModule unit -> unit
moduleUnit (HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
n1) Unit -> Unit -> Bool
forall a. Eq a => a -> a -> Bool
== Module -> Unit
forall unit. GenModule unit -> unit
moduleUnit (HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
n2)
, Name
n1 Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
/= Name
n2
, Bool
same_occ
= [Bool -> Name -> Name -> TcSolverReportInfo
SameOcc Bool
same_pkg Name
n1 Name
n2]
| Bool
otherwise
= []
mkDictErr :: HasDebugCallStack => SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkDictErr :: SolverReportErrCtxt -> [ErrorItem] -> TcM SolverReport
mkDictErr SolverReportErrCtxt
ctxt [ErrorItem]
orig_items
= Bool -> TcM SolverReport -> TcM SolverReport
forall a. HasCallStack => Bool -> a -> a
assert (Bool -> Bool
not ([ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ErrorItem]
items)) (TcM SolverReport -> TcM SolverReport)
-> TcM SolverReport -> TcM SolverReport
forall a b. (a -> b) -> a -> b
$
do { InstEnvs
inst_envs <- TcM InstEnvs
tcGetInstEnvs
; let min_items :: [ErrorItem]
min_items = [ErrorItem] -> [ErrorItem]
elim_superclasses [ErrorItem]
items
lookups :: [(ErrorItem, ClsInstLookupResult)]
lookups = (ErrorItem -> (ErrorItem, ClsInstLookupResult))
-> [ErrorItem] -> [(ErrorItem, ClsInstLookupResult)]
forall a b. (a -> b) -> [a] -> [b]
map (InstEnvs -> ErrorItem -> (ErrorItem, ClsInstLookupResult)
lookup_cls_inst InstEnvs
inst_envs) [ErrorItem]
min_items
([(ErrorItem, ClsInstLookupResult)]
no_inst_items, [(ErrorItem, ClsInstLookupResult)]
overlap_items) = ((ErrorItem, ClsInstLookupResult) -> Bool)
-> [(ErrorItem, ClsInstLookupResult)]
-> ([(ErrorItem, ClsInstLookupResult)],
[(ErrorItem, ClsInstLookupResult)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (ErrorItem, ClsInstLookupResult) -> Bool
is_no_inst [(ErrorItem, ClsInstLookupResult)]
lookups
; TcSolverReportMsg
err <- HasCallStack =>
SolverReportErrCtxt
-> (ErrorItem, ClsInstLookupResult) -> TcM TcSolverReportMsg
SolverReportErrCtxt
-> (ErrorItem, ClsInstLookupResult) -> TcM TcSolverReportMsg
mk_dict_err SolverReportErrCtxt
ctxt ([(ErrorItem, ClsInstLookupResult)]
-> (ErrorItem, ClsInstLookupResult)
forall a. [a] -> a
head ([(ErrorItem, ClsInstLookupResult)]
no_inst_items [(ErrorItem, ClsInstLookupResult)]
-> [(ErrorItem, ClsInstLookupResult)]
-> [(ErrorItem, ClsInstLookupResult)]
forall a. [a] -> [a] -> [a]
++ [(ErrorItem, ClsInstLookupResult)]
overlap_items))
; SolverReport -> TcM SolverReport
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReport -> TcM SolverReport)
-> SolverReport -> TcM SolverReport
forall a b. (a -> b) -> a -> b
$ SolverReportErrCtxt -> TcSolverReportMsg -> SolverReport
important SolverReportErrCtxt
ctxt TcSolverReportMsg
err }
where
filtered_items :: [ErrorItem]
filtered_items = (ErrorItem -> Bool) -> [ErrorItem] -> [ErrorItem]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (ErrorItem -> Bool) -> ErrorItem -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorItem -> Bool
ei_suppress) [ErrorItem]
orig_items
items :: [ErrorItem]
items | [ErrorItem] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ErrorItem]
filtered_items = [ErrorItem]
orig_items
| Bool
otherwise = [ErrorItem]
filtered_items
no_givens :: Bool
no_givens = [Implication] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (SolverReportErrCtxt -> [Implication]
getUserGivens SolverReportErrCtxt
ctxt)
is_no_inst :: (ErrorItem, ClsInstLookupResult) -> Bool
is_no_inst (ErrorItem
item, ([InstMatch]
matches, PotentialUnifiers
unifiers, [InstMatch]
_))
= Bool
no_givens
Bool -> Bool -> Bool
&& [InstMatch] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [InstMatch]
matches
Bool -> Bool -> Bool
&& (PotentialUnifiers -> Bool
nullUnifiers PotentialUnifiers
unifiers Bool -> Bool -> Bool
|| (TyCoVar -> Bool) -> [TyCoVar] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Bool -> Bool
not (Bool -> Bool) -> (TyCoVar -> Bool) -> TyCoVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TyCoVar -> Bool
isAmbiguousTyVar) (TcType -> [TyCoVar]
tyCoVarsOfTypeList (ErrorItem -> TcType
errorItemPred ErrorItem
item)))
lookup_cls_inst :: InstEnvs -> ErrorItem -> (ErrorItem, ClsInstLookupResult)
lookup_cls_inst InstEnvs
inst_envs ErrorItem
item
= (ErrorItem
item, Bool -> InstEnvs -> Class -> [TcType] -> ClsInstLookupResult
lookupInstEnv Bool
True InstEnvs
inst_envs Class
clas [TcType]
tys)
where
(Class
clas, [TcType]
tys) = HasDebugCallStack => TcType -> (Class, [TcType])
TcType -> (Class, [TcType])
getClassPredTys (ErrorItem -> TcType
errorItemPred ErrorItem
item)
elim_superclasses :: [ErrorItem] -> [ErrorItem]
elim_superclasses [ErrorItem]
items = (ErrorItem -> TcType) -> [ErrorItem] -> [ErrorItem]
forall a. (a -> TcType) -> [a] -> [a]
mkMinimalBySCs ErrorItem -> TcType
errorItemPred [ErrorItem]
items
mk_dict_err :: HasCallStack => SolverReportErrCtxt -> (ErrorItem, ClsInstLookupResult)
-> TcM TcSolverReportMsg
mk_dict_err :: SolverReportErrCtxt
-> (ErrorItem, ClsInstLookupResult) -> TcM TcSolverReportMsg
mk_dict_err SolverReportErrCtxt
ctxt (ErrorItem
item, ([InstMatch]
matches, PotentialUnifiers
unifiers, [InstMatch]
unsafe_overlapped))
| [InstMatch] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [InstMatch]
matches
= do { (SolverReportErrCtxt
_, RelevantBindings
rel_binds, ErrorItem
item) <- Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcM (SolverReportErrCtxt, RelevantBindings, ErrorItem)
relevantBindings Bool
True SolverReportErrCtxt
ctxt ErrorItem
item
; [ClsInst]
candidate_insts <- TcM [ClsInst]
get_candidate_instances
; ([ImportError]
imp_errs, [GhcHint]
field_suggestions) <- TcM ([ImportError], [GhcHint])
record_field_suggestions
; TcSolverReportMsg -> TcM TcSolverReportMsg
forall (m :: * -> *) a. Monad m => a -> m a
return (ErrorItem
-> [ClsInst]
-> RelevantBindings
-> [ImportError]
-> [GhcHint]
-> TcSolverReportMsg
cannot_resolve_msg ErrorItem
item [ClsInst]
candidate_insts RelevantBindings
rel_binds [ImportError]
imp_errs [GhcHint]
field_suggestions) }
| [InstMatch] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [InstMatch]
unsafe_overlapped
= TcSolverReportMsg -> TcM TcSolverReportMsg
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportMsg -> TcM TcSolverReportMsg)
-> TcSolverReportMsg -> TcM TcSolverReportMsg
forall a b. (a -> b) -> a -> b
$ TcSolverReportMsg
overlap_msg
| Bool
otherwise
= TcSolverReportMsg -> TcM TcSolverReportMsg
forall (m :: * -> *) a. Monad m => a -> m a
return (TcSolverReportMsg -> TcM TcSolverReportMsg)
-> TcSolverReportMsg -> TcM TcSolverReportMsg
forall a b. (a -> b) -> a -> b
$ TcSolverReportMsg
safe_haskell_msg
where
orig :: CtOrigin
orig = ErrorItem -> CtOrigin
errorItemOrigin ErrorItem
item
pred :: TcType
pred = ErrorItem -> TcType
errorItemPred ErrorItem
item
(Class
clas, [TcType]
tys) = HasDebugCallStack => TcType -> (Class, [TcType])
TcType -> (Class, [TcType])
getClassPredTys TcType
pred
ispecs :: [ClsInst]
ispecs = [ClsInst
ispec | (ClsInst
ispec, [Maybe TcType]
_) <- [InstMatch]
matches]
unsafe_ispecs :: [ClsInst]
unsafe_ispecs = [ClsInst
ispec | (ClsInst
ispec, [Maybe TcType]
_) <- [InstMatch]
unsafe_overlapped]
get_candidate_instances :: TcM [ClsInst]
get_candidate_instances :: TcM [ClsInst]
get_candidate_instances
| [TcType
ty] <- [TcType]
tys
= do { InstEnvs
instEnvs <- TcM InstEnvs
tcGetInstEnvs
; [ClsInst] -> TcM [ClsInst]
forall (m :: * -> *) a. Monad m => a -> m a
return ((ClsInst -> Bool) -> [ClsInst] -> [ClsInst]
forall a. (a -> Bool) -> [a] -> [a]
filter (TcType -> ClsInst -> Bool
is_candidate_inst TcType
ty)
(InstEnvs -> Class -> [ClsInst]
classInstances InstEnvs
instEnvs Class
clas)) }
| Bool
otherwise = [ClsInst] -> TcM [ClsInst]
forall (m :: * -> *) a. Monad m => a -> m a
return []
is_candidate_inst :: TcType -> ClsInst -> Bool
is_candidate_inst TcType
ty ClsInst
inst
| [TcType
other_ty] <- ClsInst -> [TcType]
is_tys ClsInst
inst
, Just (TyCon
tc1, [TcType]
_) <- HasCallStack => TcType -> Maybe (TyCon, [TcType])
TcType -> Maybe (TyCon, [TcType])
tcSplitTyConApp_maybe TcType
ty
, Just (TyCon
tc2, [TcType]
_) <- HasCallStack => TcType -> Maybe (TyCon, [TcType])
TcType -> Maybe (TyCon, [TcType])
tcSplitTyConApp_maybe TcType
other_ty
= let n1 :: Name
n1 = TyCon -> Name
tyConName TyCon
tc1
n2 :: Name
n2 = TyCon -> Name
tyConName TyCon
tc2
different_names :: Bool
different_names = Name
n1 Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
/= Name
n2
same_occ_names :: Bool
same_occ_names = Name -> OccName
nameOccName Name
n1 OccName -> OccName -> Bool
forall a. Eq a => a -> a -> Bool
== Name -> OccName
nameOccName Name
n2
in Bool
different_names Bool -> Bool -> Bool
&& Bool
same_occ_names
| Bool
otherwise = Bool
False
record_field_suggestions :: TcM ([ImportError], [GhcHint])
record_field_suggestions :: TcM ([ImportError], [GhcHint])
record_field_suggestions = ((OccName -> TcM ([ImportError], [GhcHint]))
-> Maybe OccName -> TcM ([ImportError], [GhcHint]))
-> Maybe OccName
-> (OccName -> TcM ([ImportError], [GhcHint]))
-> TcM ([ImportError], [GhcHint])
forall a b c. (a -> b -> c) -> b -> a -> c
flip (TcM ([ImportError], [GhcHint])
-> (OccName -> TcM ([ImportError], [GhcHint]))
-> Maybe OccName
-> TcM ([ImportError], [GhcHint])
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (TcM ([ImportError], [GhcHint])
-> (OccName -> TcM ([ImportError], [GhcHint]))
-> Maybe OccName
-> TcM ([ImportError], [GhcHint]))
-> TcM ([ImportError], [GhcHint])
-> (OccName -> TcM ([ImportError], [GhcHint]))
-> Maybe OccName
-> TcM ([ImportError], [GhcHint])
forall a b. (a -> b) -> a -> b
$ ([ImportError], [GhcHint]) -> TcM ([ImportError], [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [GhcHint]
noHints)) Maybe OccName
record_field ((OccName -> TcM ([ImportError], [GhcHint]))
-> TcM ([ImportError], [GhcHint]))
-> (OccName -> TcM ([ImportError], [GhcHint]))
-> TcM ([ImportError], [GhcHint])
forall a b. (a -> b) -> a -> b
$ \OccName
name ->
do { GlobalRdrEnv
glb_env <- TcRn GlobalRdrEnv
getGlobalRdrEnv
; LocalRdrEnv
lcl_env <- RnM LocalRdrEnv
getLocalRdrEnv
; if GlobalRdrEnv -> LocalRdrEnv -> OccName -> Bool
occ_name_in_scope GlobalRdrEnv
glb_env LocalRdrEnv
lcl_env OccName
name
then ([ImportError], [GhcHint]) -> TcM ([ImportError], [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [GhcHint]
noHints)
else do { DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; ImportAvails
imp_info <- TcRn ImportAvails
getImports
; Module
curr_mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; HomePackageTable
hpt <- TcRnIf TcGblEnv TcLclEnv HomePackageTable
forall gbl lcl. TcRnIf gbl lcl HomePackageTable
getHpt
; ([ImportError], [GhcHint]) -> TcM ([ImportError], [GhcHint])
forall (m :: * -> *) a. Monad m => a -> m a
return (WhatLooking
-> DynFlags
-> HomePackageTable
-> Module
-> GlobalRdrEnv
-> LocalRdrEnv
-> ImportAvails
-> RdrName
-> ([ImportError], [GhcHint])
unknownNameSuggestions WhatLooking
WL_RecField DynFlags
dflags HomePackageTable
hpt Module
curr_mod
GlobalRdrEnv
glb_env LocalRdrEnv
emptyLocalRdrEnv ImportAvails
imp_info (OccName -> RdrName
mkRdrUnqual OccName
name)) } }
occ_name_in_scope :: GlobalRdrEnv -> LocalRdrEnv -> OccName -> Bool
occ_name_in_scope GlobalRdrEnv
glb_env LocalRdrEnv
lcl_env OccName
occ_name = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$
[GlobalRdrElt] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (GlobalRdrEnv -> OccName -> [GlobalRdrElt]
lookupGlobalRdrEnv GlobalRdrEnv
glb_env OccName
occ_name) Bool -> Bool -> Bool
&&
Maybe Name -> Bool
forall a. Maybe a -> Bool
isNothing (LocalRdrEnv -> OccName -> Maybe Name
lookupLocalRdrOcc LocalRdrEnv
lcl_env OccName
occ_name)
record_field :: Maybe OccName
record_field = case CtOrigin
orig of
HasFieldOrigin FastString
name -> OccName -> Maybe OccName
forall a. a -> Maybe a
Just (FastString -> OccName
mkVarOccFS FastString
name)
CtOrigin
_ -> Maybe OccName
forall a. Maybe a
Nothing
cannot_resolve_msg :: ErrorItem -> [ClsInst] -> RelevantBindings
-> [ImportError] -> [GhcHint] -> TcSolverReportMsg
cannot_resolve_msg :: ErrorItem
-> [ClsInst]
-> RelevantBindings
-> [ImportError]
-> [GhcHint]
-> TcSolverReportMsg
cannot_resolve_msg ErrorItem
item [ClsInst]
candidate_insts RelevantBindings
binds [ImportError]
imp_errs [GhcHint]
field_suggestions
= ErrorItem
-> [ClsInst]
-> [ClsInst]
-> [ImportError]
-> [GhcHint]
-> RelevantBindings
-> TcSolverReportMsg
CannotResolveInstance ErrorItem
item (PotentialUnifiers -> [ClsInst]
getPotentialUnifiers PotentialUnifiers
unifiers) [ClsInst]
candidate_insts [ImportError]
imp_errs [GhcHint]
field_suggestions RelevantBindings
binds
overlap_msg, safe_haskell_msg :: TcSolverReportMsg
overlap_msg :: TcSolverReportMsg
overlap_msg
= Bool -> TcSolverReportMsg -> TcSolverReportMsg
forall a. HasCallStack => Bool -> a -> a
assert (Bool -> Bool
not ([InstMatch] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [InstMatch]
matches)) (TcSolverReportMsg -> TcSolverReportMsg)
-> TcSolverReportMsg -> TcSolverReportMsg
forall a b. (a -> b) -> a -> b
$ ErrorItem -> [ClsInst] -> [ClsInst] -> TcSolverReportMsg
OverlappingInstances ErrorItem
item [ClsInst]
ispecs (PotentialUnifiers -> [ClsInst]
getPotentialUnifiers PotentialUnifiers
unifiers)
safe_haskell_msg :: TcSolverReportMsg
safe_haskell_msg
= Bool -> TcSolverReportMsg -> TcSolverReportMsg
forall a. HasCallStack => Bool -> a -> a
assert ([InstMatch]
matches [InstMatch] -> Int -> Bool
forall a. [a] -> Int -> Bool
`lengthIs` Int
1 Bool -> Bool -> Bool
&& Bool -> Bool
not ([ClsInst] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ClsInst]
unsafe_ispecs)) (TcSolverReportMsg -> TcSolverReportMsg)
-> TcSolverReportMsg -> TcSolverReportMsg
forall a b. (a -> b) -> a -> b
$
ErrorItem -> [ClsInst] -> [ClsInst] -> TcSolverReportMsg
UnsafeOverlap ErrorItem
item [ClsInst]
ispecs [ClsInst]
unsafe_ispecs
relevantBindings :: Bool
-> SolverReportErrCtxt -> ErrorItem
-> TcM (SolverReportErrCtxt, RelevantBindings, ErrorItem)
relevantBindings :: Bool
-> SolverReportErrCtxt
-> ErrorItem
-> TcM (SolverReportErrCtxt, RelevantBindings, ErrorItem)
relevantBindings Bool
want_filtering SolverReportErrCtxt
ctxt ErrorItem
item
= do { String -> SDoc -> TcM ()
traceTc String
"relevantBindings" (ErrorItem -> SDoc
forall a. Outputable a => a -> SDoc
ppr ErrorItem
item)
; (TidyEnv
env1, CtOrigin
tidy_orig) <- TidyEnv -> CtOrigin -> TcM (TidyEnv, CtOrigin)
zonkTidyOrigin (SolverReportErrCtxt -> TidyEnv
cec_tidy SolverReportErrCtxt
ctxt) (CtLoc -> CtOrigin
ctLocOrigin CtLoc
loc)
; let extra_tvs :: TyCoVarSet
extra_tvs = case CtOrigin
tidy_orig of
KindEqOrigin TcType
t1 TcType
t2 CtOrigin
_ Maybe TypeOrKind
_ -> [TcType] -> TyCoVarSet
tyCoVarsOfTypes [TcType
t1,TcType
t2]
CtOrigin
_ -> TyCoVarSet
emptyVarSet
ct_fvs :: TyCoVarSet
ct_fvs = TcType -> TyCoVarSet
tyCoVarsOfType (ErrorItem -> TcType
errorItemPred ErrorItem
item) TyCoVarSet -> TyCoVarSet -> TyCoVarSet
`unionVarSet` TyCoVarSet
extra_tvs
loc' :: CtLoc
loc' = CtLoc -> CtOrigin -> CtLoc
setCtLocOrigin CtLoc
loc CtOrigin
tidy_orig
item' :: ErrorItem
item' = ErrorItem
item { ei_loc :: CtLoc
ei_loc = CtLoc
loc' }
; (TidyEnv
env2, NameEnv TcType
lcl_name_cache) <- TidyEnv -> [TcLclEnv] -> TcM (TidyEnv, NameEnv TcType)
zonkTidyTcLclEnvs TidyEnv
env1 [TcLclEnv
lcl_env]
; RelevantBindings
relev_bds <- Bool
-> TcLclEnv -> NameEnv TcType -> TyCoVarSet -> TcM RelevantBindings
relevant_bindings Bool
want_filtering TcLclEnv
lcl_env NameEnv TcType
lcl_name_cache TyCoVarSet
ct_fvs
; let ctxt' :: SolverReportErrCtxt
ctxt' = SolverReportErrCtxt
ctxt { cec_tidy :: TidyEnv
cec_tidy = TidyEnv
env2 }
; (SolverReportErrCtxt, RelevantBindings, ErrorItem)
-> TcM (SolverReportErrCtxt, RelevantBindings, ErrorItem)
forall (m :: * -> *) a. Monad m => a -> m a
return (SolverReportErrCtxt
ctxt', RelevantBindings
relev_bds, ErrorItem
item') }
where
loc :: CtLoc
loc = ErrorItem -> CtLoc
errorItemCtLoc ErrorItem
item
lcl_env :: TcLclEnv
lcl_env = CtLoc -> TcLclEnv
ctLocEnv CtLoc
loc
relevant_bindings :: Bool
-> TcLclEnv
-> NameEnv Type
-> TyCoVarSet
-> TcM RelevantBindings
relevant_bindings :: Bool
-> TcLclEnv -> NameEnv TcType -> TyCoVarSet -> TcM RelevantBindings
relevant_bindings Bool
want_filtering TcLclEnv
lcl_env NameEnv TcType
lcl_name_env TyCoVarSet
ct_tvs
= do { DynFlags
dflags <- IOEnv (Env TcGblEnv TcLclEnv) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
; String -> SDoc -> TcM ()
traceTc String
"relevant_bindings" (SDoc -> TcM ()) -> SDoc -> TcM ()
forall a b. (a -> b) -> a -> b
$
[SDoc] -> SDoc
vcat [ TyCoVarSet -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVarSet
ct_tvs
, (SDoc -> SDoc) -> [SDoc] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas SDoc -> SDoc
forall a. a -> a
id [ TyCoVar -> SDoc
forall a. Outputable a => a -> SDoc
ppr TyCoVar
id SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr (TyCoVar -> TcType
idType TyCoVar
id)
| TcIdBndr TyCoVar
id TopLevelFlag
_ <- TcLclEnv -> [TcBinder]
tcl_bndrs TcLclEnv
lcl_env ]
, (SDoc -> SDoc) -> [SDoc] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas SDoc -> SDoc
forall a. a -> a
id
[ Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
id | TcIdBndr_ExpType Name
id ExpType
_ TopLevelFlag
_ <- TcLclEnv -> [TcBinder]
tcl_bndrs TcLclEnv
lcl_env ] ]
; DynFlags
-> Maybe Int
-> TyCoVarSet
-> RelevantBindings
-> [TcBinder]
-> TcM RelevantBindings
go DynFlags
dflags (DynFlags -> Maybe Int
maxRelevantBinds DynFlags
dflags)
TyCoVarSet
emptyVarSet ([(Name, TcType)] -> Bool -> RelevantBindings
RelevantBindings [] Bool
False)
([TcBinder] -> [TcBinder]
forall a. HasOccName a => [a] -> [a]
removeBindingShadowing ([TcBinder] -> [TcBinder]) -> [TcBinder] -> [TcBinder]
forall a b. (a -> b) -> a -> b
$ TcLclEnv -> [TcBinder]
tcl_bndrs TcLclEnv
lcl_env)
}
where
run_out :: Maybe Int -> Bool
run_out :: Maybe Int -> Bool
run_out Maybe Int
Nothing = Bool
False
run_out (Just Int
n) = Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0
dec_max :: Maybe Int -> Maybe Int
dec_max :: Maybe Int -> Maybe Int
dec_max = (Int -> Int) -> Maybe Int -> Maybe Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\Int
n -> Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
go :: DynFlags -> Maybe Int -> TcTyVarSet
-> RelevantBindings
-> [TcBinder]
-> TcM RelevantBindings
go :: DynFlags
-> Maybe Int
-> TyCoVarSet
-> RelevantBindings
-> [TcBinder]
-> TcM RelevantBindings
go DynFlags
_ Maybe Int
_ TyCoVarSet
_ (RelevantBindings [(Name, TcType)]
bds Bool
discards) []
= RelevantBindings -> TcM RelevantBindings
forall (m :: * -> *) a. Monad m => a -> m a
return (RelevantBindings -> TcM RelevantBindings)
-> RelevantBindings -> TcM RelevantBindings
forall a b. (a -> b) -> a -> b
$ [(Name, TcType)] -> Bool -> RelevantBindings
RelevantBindings ([(Name, TcType)] -> [(Name, TcType)]
forall a. [a] -> [a]
reverse [(Name, TcType)]
bds) Bool
discards
go DynFlags
dflags Maybe Int
n_left TyCoVarSet
tvs_seen rels :: RelevantBindings
rels@(RelevantBindings [(Name, TcType)]
bds Bool
discards) (TcBinder
tc_bndr : [TcBinder]
tc_bndrs)
= case TcBinder
tc_bndr of
TcTvBndr {} -> TcM RelevantBindings
discard_it
TcIdBndr TyCoVar
id TopLevelFlag
top_lvl -> Name -> TopLevelFlag -> TcM RelevantBindings
go2 (TyCoVar -> Name
idName TyCoVar
id) TopLevelFlag
top_lvl
TcIdBndr_ExpType Name
name ExpType
et TopLevelFlag
top_lvl ->
do { Maybe TcType
mb_ty <- ExpType -> TcM (Maybe TcType)
readExpType_maybe ExpType
et
; case Maybe TcType
mb_ty of
Just TcType
_ty -> Name -> TopLevelFlag -> TcM RelevantBindings
go2 Name
name TopLevelFlag
top_lvl
Maybe TcType
Nothing -> TcM RelevantBindings
discard_it
}
where
discard_it :: TcM RelevantBindings
discard_it = DynFlags
-> Maybe Int
-> TyCoVarSet
-> RelevantBindings
-> [TcBinder]
-> TcM RelevantBindings
go DynFlags
dflags Maybe Int
n_left TyCoVarSet
tvs_seen RelevantBindings
rels [TcBinder]
tc_bndrs
go2 :: Name -> TopLevelFlag -> TcM RelevantBindings
go2 Name
id_name TopLevelFlag
top_lvl
= do { let tidy_ty :: TcType
tidy_ty = case NameEnv TcType -> Name -> Maybe TcType
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv NameEnv TcType
lcl_name_env Name
id_name of
Just TcType
tty -> TcType
tty
Maybe TcType
Nothing -> String -> SDoc -> TcType
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"relevant_bindings" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
id_name)
; String -> SDoc -> TcM ()
traceTc String
"relevantBindings 1" (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
id_name SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> TcType -> SDoc
forall a. Outputable a => a -> SDoc
ppr TcType
tidy_ty)
; let id_tvs :: TyCoVarSet
id_tvs = TcType -> TyCoVarSet
tyCoVarsOfType TcType
tidy_ty
bd :: (Name, TcType)
bd = (Name
id_name, TcType
tidy_ty)
new_seen :: TyCoVarSet
new_seen = TyCoVarSet
tvs_seen TyCoVarSet -> TyCoVarSet -> TyCoVarSet
`unionVarSet` TyCoVarSet
id_tvs
; if (Bool
want_filtering Bool -> Bool -> Bool
&& Bool -> Bool
not (DynFlags -> Bool
hasPprDebug DynFlags
dflags)
Bool -> Bool -> Bool
&& TyCoVarSet
id_tvs TyCoVarSet -> TyCoVarSet -> Bool
`disjointVarSet` TyCoVarSet
ct_tvs)
then TcM RelevantBindings
discard_it
else if TopLevelFlag -> Bool
isTopLevel TopLevelFlag
top_lvl Bool -> Bool -> Bool
&& Bool -> Bool
not (Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Int
n_left)
then TcM RelevantBindings
discard_it
else if Maybe Int -> Bool
run_out Maybe Int
n_left Bool -> Bool -> Bool
&& TyCoVarSet
id_tvs TyCoVarSet -> TyCoVarSet -> Bool
`subVarSet` TyCoVarSet
tvs_seen
then DynFlags
-> Maybe Int
-> TyCoVarSet
-> RelevantBindings
-> [TcBinder]
-> TcM RelevantBindings
go DynFlags
dflags Maybe Int
n_left TyCoVarSet
tvs_seen ([(Name, TcType)] -> Bool -> RelevantBindings
RelevantBindings [(Name, TcType)]
bds Bool
True)
[TcBinder]
tc_bndrs
else DynFlags
-> Maybe Int
-> TyCoVarSet
-> RelevantBindings
-> [TcBinder]
-> TcM RelevantBindings
go DynFlags
dflags (Maybe Int -> Maybe Int
dec_max Maybe Int
n_left) TyCoVarSet
new_seen
([(Name, TcType)] -> Bool -> RelevantBindings
RelevantBindings ((Name, TcType)
bd(Name, TcType) -> [(Name, TcType)] -> [(Name, TcType)]
forall a. a -> [a] -> [a]
:[(Name, TcType)]
bds) Bool
discards) [TcBinder]
tc_bndrs }
warnDefaulting :: TcTyVar -> [Ct] -> Type -> TcM ()
warnDefaulting :: TyCoVar -> [Ct] -> TcType -> TcM ()
warnDefaulting TyCoVar
_ [] TcType
_
= String -> TcM ()
forall a. String -> a
panic String
"warnDefaulting: empty Wanteds"
warnDefaulting TyCoVar
the_tv wanteds :: [Ct]
wanteds@(Ct
ct:[Ct]
_) TcType
default_ty
= do { Bool
warn_default <- WarningFlag -> TcRnIf TcGblEnv TcLclEnv Bool
forall gbl lcl. WarningFlag -> TcRnIf gbl lcl Bool
woptM WarningFlag
Opt_WarnTypeDefaults
; TidyEnv
env0 <- TcM TidyEnv
tcInitTidyEnv
; let filtered :: [Ct]
filtered = (Ct -> Bool) -> [Ct] -> [Ct]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Ct -> Bool) -> Ct -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CtOrigin -> Bool
isWantedSuperclassOrigin (CtOrigin -> Bool) -> (Ct -> CtOrigin) -> Ct -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ct -> CtOrigin
ctOrigin) [Ct]
wanteds
tidy_env :: TidyEnv
tidy_env = TidyEnv -> [TyCoVar] -> TidyEnv
tidyFreeTyCoVars TidyEnv
env0 ([TyCoVar] -> TidyEnv) -> [TyCoVar] -> TidyEnv
forall a b. (a -> b) -> a -> b
$
Cts -> [TyCoVar]
tyCoVarsOfCtsList ([Ct] -> Cts
forall a. [a] -> Bag a
listToBag [Ct]
filtered)
tidy_wanteds :: [Ct]
tidy_wanteds = (Ct -> Ct) -> [Ct] -> [Ct]
forall a b. (a -> b) -> [a] -> [b]
map (TidyEnv -> Ct -> Ct
tidyCt TidyEnv
tidy_env) [Ct]
filtered
tidy_tv :: Maybe TyCoVar
tidy_tv = VarEnv TyCoVar -> TyCoVar -> Maybe TyCoVar
forall a. VarEnv a -> TyCoVar -> Maybe a
lookupVarEnv (TidyEnv -> VarEnv TyCoVar
forall a b. (a, b) -> b
snd TidyEnv
tidy_env) TyCoVar
the_tv
diag :: TcRnMessage
diag = [Ct] -> Maybe TyCoVar -> TcType -> TcRnMessage
TcRnWarnDefaulting [Ct]
tidy_wanteds Maybe TyCoVar
tidy_tv TcType
default_ty
loc :: CtLoc
loc = Ct -> CtLoc
ctLoc Ct
ct
; CtLoc -> TcM () -> TcM ()
forall a. CtLoc -> TcM a -> TcM a
setCtLocM CtLoc
loc (TcM () -> TcM ()) -> TcM () -> TcM ()
forall a b. (a -> b) -> a -> b
$ Bool -> TcRnMessage -> TcM ()
diagnosticTc Bool
warn_default TcRnMessage
diag }
solverReportMsg_ExpectedActuals :: TcSolverReportMsg -> [(Type, Type)]
solverReportMsg_ExpectedActuals :: TcSolverReportMsg -> [(TcType, TcType)]
solverReportMsg_ExpectedActuals
= \case
TcReportWithInfo TcSolverReportMsg
msg NonEmpty TcSolverReportInfo
infos ->
TcSolverReportMsg -> [(TcType, TcType)]
solverReportMsg_ExpectedActuals TcSolverReportMsg
msg
[(TcType, TcType)] -> [(TcType, TcType)] -> [(TcType, TcType)]
forall a. [a] -> [a] -> [a]
++ (TcSolverReportInfo -> [(TcType, TcType)]
solverReportInfo_ExpectedActuals (TcSolverReportInfo -> [(TcType, TcType)])
-> [TcSolverReportInfo] -> [(TcType, TcType)]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< NonEmpty TcSolverReportInfo -> [TcSolverReportInfo]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList NonEmpty TcSolverReportInfo
infos)
Mismatch { mismatch_ty1 :: TcSolverReportMsg -> TcType
mismatch_ty1 = TcType
exp, mismatch_ty2 :: TcSolverReportMsg -> TcType
mismatch_ty2 = TcType
act } ->
[(TcType
exp, TcType
act)]
KindMismatch { kmismatch_expected :: TcSolverReportMsg -> TcType
kmismatch_expected = TcType
exp, kmismatch_actual :: TcSolverReportMsg -> TcType
kmismatch_actual = TcType
act } ->
[(TcType
exp, TcType
act)]
TypeEqMismatch { teq_mismatch_expected :: TcSolverReportMsg -> TcType
teq_mismatch_expected = TcType
exp, teq_mismatch_actual :: TcSolverReportMsg -> TcType
teq_mismatch_actual = TcType
act } ->
[(TcType
exp,TcType
act)]
TcSolverReportMsg
_ -> []
solverReportInfo_ExpectedActuals :: TcSolverReportInfo -> [(Type, Type)]
solverReportInfo_ExpectedActuals :: TcSolverReportInfo -> [(TcType, TcType)]
solverReportInfo_ExpectedActuals
= \case
ExpectedActual { ea_expected :: TcSolverReportInfo -> TcType
ea_expected = TcType
exp, ea_actual :: TcSolverReportInfo -> TcType
ea_actual = TcType
act } ->
[(TcType
exp, TcType
act)]
ExpectedActualAfterTySynExpansion
{ ea_expanded_expected :: TcSolverReportInfo -> TcType
ea_expanded_expected = TcType
exp, ea_expanded_actual :: TcSolverReportInfo -> TcType
ea_expanded_actual = TcType
act } ->
[(TcType
exp, TcType
act)]
TcSolverReportInfo
_ -> []