| ... |
... |
@@ -256,21 +256,16 @@ report_unsolved type_errors expr_holes |
|
256
|
256
|
|
|
257
|
257
|
; warn_redundant <- woptM Opt_WarnRedundantConstraints
|
|
258
|
258
|
; exp_syns <- goptM Opt_PrintExpandedSynonyms
|
|
259
|
|
- ; let err_ctxt = CEC { cec_encl = []
|
|
260
|
|
- , cec_tidy = tidy_env
|
|
261
|
|
- , cec_defer_type_errors = type_errors
|
|
262
|
|
- , cec_expr_holes = expr_holes
|
|
263
|
|
- , cec_type_holes = type_holes
|
|
|
259
|
+ ; let err_ctxt = CEC { cec_encl = []
|
|
|
260
|
+ , cec_tidy = tidy_env
|
|
|
261
|
+ , cec_defer_type_errors = type_errors
|
|
|
262
|
+ , cec_expr_holes = expr_holes
|
|
|
263
|
+ , cec_type_holes = type_holes
|
|
264
|
264
|
, cec_out_of_scope_holes = out_of_scope_holes
|
|
265
|
|
- , cec_suppress = insolubleWC wanted
|
|
266
|
|
- -- See (SLIE1) in
|
|
267
|
|
- -- Note [cec_suppress: suppressing less-important error messages]
|
|
268
|
|
- -- Suppress low-priority errors if there are insoluble errors
|
|
269
|
|
- -- anywhere in the treee. See #15539 and c.f. setting ic_status
|
|
270
|
|
- -- in GHC.Tc.Solver.setImplicationStatus
|
|
271
|
|
- , cec_warn_redundant = warn_redundant
|
|
272
|
|
- , cec_expand_syns = exp_syns
|
|
273
|
|
- , cec_binds = binds_var }
|
|
|
265
|
+ , cec_suppress = False
|
|
|
266
|
+ , cec_warn_redundant = warn_redundant
|
|
|
267
|
+ , cec_expand_syns = exp_syns
|
|
|
268
|
+ , cec_binds = binds_var }
|
|
274
|
269
|
|
|
275
|
270
|
; tc_lvl <- getTcLevel
|
|
276
|
271
|
; reportWanteds err_ctxt tc_lvl wanted
|
| ... |
... |
@@ -689,7 +684,7 @@ reportWanteds ctxt tc_lvl wc@(WC { wc_simple = simples, wc_impl = implics |
|
689
|
684
|
|
|
690
|
685
|
-- Don't suppress holes or concreteness errors unless we have scope errors
|
|
691
|
686
|
; reportHoles tidy_items ctxt_for_insols other_holes
|
|
692
|
|
- ; reportNotConcreteErrs ctxt_for_insols not_conc_errs
|
|
|
687
|
+ ; reportNotConcreteErrs ctxt_for_insols not_conc_errs
|
|
693
|
688
|
|
|
694
|
689
|
-- We only want to report multiplicity coercion errors for multiplicity
|
|
695
|
690
|
-- constraints which are /solved/ with a non-reflexivity coercion. We
|
| ... |
... |
@@ -699,27 +694,28 @@ reportWanteds ctxt tc_lvl wc@(WC { wc_simple = simples, wc_impl = implics |
|
699
|
694
|
; when (null simples) $
|
|
700
|
695
|
reportMultiplicityCoercionErrs ctxt_for_insols mult_co_errs
|
|
701
|
696
|
|
|
702
|
|
- -- Now the main batch of utterly-wrong things
|
|
|
697
|
+ -- Now the constraints that give serious errors
|
|
703
|
698
|
-- Like Int ~ Bool (incl nullary TyCons)
|
|
704
|
699
|
-- or Int ~ t a (AppTy on one side)
|
|
705
|
|
- ; (ctxt1, items1) <- tryReporters ctxt_for_insols report1 tidy_items
|
|
706
|
|
-
|
|
707
|
|
- -- Now all the other constraints. We suppress errors here if
|
|
708
|
|
- -- any of the first batch failed (ctxt1), or if the enclosing context
|
|
709
|
|
- -- says to suppress AND there are local insolubles that are all suppressed.
|
|
710
|
|
- -- See (SLIE3) in Note [cec_suppress: suppressing less-important error messages]
|
|
711
|
|
- ; let insols = filter ei_insoluble tidy_items
|
|
712
|
|
- all_insols_suppressed | null insols = False
|
|
713
|
|
- | otherwise = all ei_suppress insols
|
|
714
|
|
- ctxt2 = ctxt1 { cec_suppress = (cec_suppress ctxt && not all_insols_suppressed)
|
|
715
|
|
- || cec_suppress ctxt1 }
|
|
716
|
|
- ; (_, leftovers) <- tryReporters ctxt2 report2 items1
|
|
|
700
|
+ ; (items1, no_serious_errs)
|
|
|
701
|
+ <- askNoErrs $
|
|
|
702
|
+ tryReporters ctxt_for_insols serious_reporters tidy_items
|
|
|
703
|
+
|
|
|
704
|
+ -- Now take account of the inherited cec_suppress, and augment it
|
|
|
705
|
+ -- to suppress further errors if we have found any serious errors locally
|
|
|
706
|
+ ; let suppress_for_rest = cec_suppress ctxt
|
|
|
707
|
+ || not no_out_of_scope
|
|
|
708
|
+ || not no_serious_errs
|
|
|
709
|
+ ctxt_for_rest = ctxt { cec_suppress = suppress_for_rest }
|
|
|
710
|
+
|
|
|
711
|
+ -- Next, deal with the less-serious constraints
|
|
|
712
|
+ ; leftovers <- tryReporters ctxt_for_rest less_serious_reporters items1
|
|
717
|
713
|
; massertPpr (null leftovers)
|
|
718
|
714
|
(text "The following unsolved Wanted constraints \
|
|
719
|
715
|
\have not been reported to the user:"
|
|
720
|
716
|
$$ ppr leftovers)
|
|
721
|
717
|
|
|
722
|
|
- ; mapBagM_ (reportImplic ctxt2) implics
|
|
|
718
|
+ ; mapBagM_ (reportImplic ctxt_for_rest) implics
|
|
723
|
719
|
-- NB ctxt2: don't suppress inner insolubles if there's only a
|
|
724
|
720
|
-- wanted insoluble here; but do suppress inner insolubles
|
|
725
|
721
|
-- if there's a *given* insoluble here (= inaccessible code)
|
| ... |
... |
@@ -745,59 +741,58 @@ reportWanteds ctxt tc_lvl wc@(WC { wc_simple = simples, wc_impl = implics |
|
745
|
741
|
DE_Multiplicity mult_co loc
|
|
746
|
742
|
-> (es1, es2, es3, (mult_co, loc):es4)
|
|
747
|
743
|
|
|
748
|
|
- -- report1: ones that should *not* be suppressed by cec_suppress,
|
|
749
|
|
- -- (i.e. by an insoluble somewhere else in the tree)
|
|
750
|
|
- -- It's crucial that anything that is considered insoluble
|
|
751
|
|
- -- (see GHC.Tc.Utils.insolublWantedCt) is caught here, otherwise
|
|
752
|
|
- -- we might suppress its error message, and proceed on past
|
|
753
|
|
- -- type checking to get a Lint error later
|
|
754
|
|
- report1 = [ -- We put implicit lifting errors first, because are solid errors
|
|
755
|
|
- -- See "Implicit lifting" in GHC.Tc.Gen.Splice
|
|
756
|
|
- -- Note [Lifecycle of an untyped splice, and PendingRnSplice]
|
|
757
|
|
- ("implicit lifting", is_implicit_lifting, True, mkImplicitLiftingReporter)
|
|
758
|
|
-
|
|
759
|
|
- -- Next, solid equality errors
|
|
760
|
|
- , given_eq_spec
|
|
761
|
|
- , ("insoluble2", utterly_wrong, True, mkGroupReporter mkEqErr)
|
|
762
|
|
- , ("skolem eq1", very_wrong, True, mkSkolReporter)
|
|
763
|
|
- , ("FixedRuntimeRep", is_FRR, True, mkGroupReporter mkFRRErr)
|
|
764
|
|
- , ("skolem eq2", skolem_eq, True, mkSkolReporter)
|
|
765
|
|
-
|
|
766
|
|
- -- Next, custom type errors
|
|
767
|
|
- -- See Note [Custom type errors in constraints] in GHC.Tc.Types.Constraint
|
|
768
|
|
- --
|
|
769
|
|
- -- Put custom type errors /after/ solid equality errors. In #26255 we
|
|
770
|
|
- -- had a custom error (T <= F alpha) which was suppressing a far more
|
|
771
|
|
- -- informative (K Int ~ [K alpha]). That mismatch between K and [] is
|
|
772
|
|
- -- definitely wrong; and if it was fixed we'd know alpha:=Int, and hence
|
|
773
|
|
- -- perhaps be able to solve T <= F alpha, by reducing F Int.
|
|
774
|
|
- --
|
|
775
|
|
- -- But put custom type errors /before/ "non-tv eq", because if we have
|
|
776
|
|
- -- () ~ TypeError blah
|
|
777
|
|
- -- we want to report it as a custom error, /not/ as a mis-match
|
|
778
|
|
- -- between TypeError and ()! Also see the Assert example
|
|
779
|
|
- -- in Note [Custom type errors in constraints]
|
|
780
|
|
- , ("custom_error", is_user_type_error, True, mkUserTypeErrorReporter)
|
|
781
|
|
- -- (Handles TypeError and Unsatisfiable)
|
|
782
|
|
-
|
|
783
|
|
- -- "non-tv-eq": equalities (ty1 ~ ty2) where ty1 is not a tyvar
|
|
784
|
|
- , ("non-tv eq", non_tv_eq, True, mkSkolReporter)
|
|
785
|
|
-
|
|
786
|
|
- -- The only remaining equalities are alpha ~ ty,
|
|
787
|
|
- -- where alpha is untouchable; and representational equalities
|
|
788
|
|
- -- Prefer homogeneous equalities over hetero, because the
|
|
789
|
|
- -- former might be holding up the latter.
|
|
790
|
|
- -- See Note [Equalities with heterogeneous kinds] in GHC.Tc.Solver.Equality
|
|
791
|
|
- , ("Homo eqs", is_homo_equality, True, mkGroupReporter mkEqErr)
|
|
792
|
|
- , ("Other eqs", is_equality, True, mkGroupReporter mkEqErr)
|
|
793
|
|
-
|
|
794
|
|
- , ("Insoluble fundeps", is_insoluble, True, mkGroupReporter mkDictErr)
|
|
795
|
|
- ]
|
|
796
|
|
-
|
|
797
|
|
- -- report2: we suppress these if there are insolubles elsewhere in the tree
|
|
798
|
|
- report2 = [ ("Irreds", is_irred, False, mkGroupReporter mkIrredErr)
|
|
799
|
|
- , ("Dicts", is_dict, False, mkGroupReporter mkDictErr)
|
|
800
|
|
- , ("Quantified", is_qc, False, mkGroupReporter mkQCErr) ]
|
|
|
744
|
+ --serious_reporters: ones that should *not* be suppressed by cec_suppress,
|
|
|
745
|
+ -- (i.e. by an insoluble somewhere else in the tree)
|
|
|
746
|
+ serious_reporters
|
|
|
747
|
+ = [ -- We put implicit lifting errors first, because are solid errors
|
|
|
748
|
+ -- See "Implicit lifting" in GHC.Tc.Gen.Splice
|
|
|
749
|
+ -- Note [Lifecycle of an untyped splice, and PendingRnSplice]
|
|
|
750
|
+ ("implicit lifting", is_implicit_lifting, True, mkImplicitLiftingReporter)
|
|
|
751
|
+
|
|
|
752
|
+ -- Next, solid equality errors
|
|
|
753
|
+ , given_eq_spec
|
|
|
754
|
+ , ("insoluble2", utterly_wrong, True, mkGroupReporter mkEqErr)
|
|
|
755
|
+ , ("skolem eq1", very_wrong, True, mkSkolReporter)
|
|
|
756
|
+ , ("FixedRuntimeRep", is_FRR, True, mkGroupReporter mkFRRErr)
|
|
|
757
|
+ , ("skolem eq2", skolem_eq, True, mkSkolReporter)
|
|
|
758
|
+
|
|
|
759
|
+ -- Next, custom type errors
|
|
|
760
|
+ -- See Note [Custom type errors in constraints] in GHC.Tc.Types.Constraint
|
|
|
761
|
+ --
|
|
|
762
|
+ -- Put custom type errors /after/ solid equality errors. In #26255 we
|
|
|
763
|
+ -- had a custom error (T <= F alpha) which was suppressing a far more
|
|
|
764
|
+ -- informative (K Int ~ [K alpha]). That mismatch between K and [] is
|
|
|
765
|
+ -- definitely wrong; and if it was fixed we'd know alpha:=Int, and hence
|
|
|
766
|
+ -- perhaps be able to solve T <= F alpha, by reducing F Int.
|
|
|
767
|
+ --
|
|
|
768
|
+ -- But put custom type errors /before/ "non-tv eq", because if we have
|
|
|
769
|
+ -- () ~ TypeError blah
|
|
|
770
|
+ -- we want to report it as a custom error, /not/ as a mis-match
|
|
|
771
|
+ -- between TypeError and ()! Also see the Assert example
|
|
|
772
|
+ -- in Note [Custom type errors in constraints]
|
|
|
773
|
+ , ("custom_error", is_user_type_error, True, mkUserTypeErrorReporter)
|
|
|
774
|
+ -- (Handles TypeError and Unsatisfiable)
|
|
|
775
|
+
|
|
|
776
|
+ -- "non-tv-eq": equalities (ty1 ~ ty2) where ty1 is not a tyvar
|
|
|
777
|
+ , ("non-tv eq", non_tv_eq, True, mkSkolReporter)
|
|
|
778
|
+
|
|
|
779
|
+ -- The only remaining equalities are alpha ~ ty,
|
|
|
780
|
+ -- where alpha is untouchable; and representational equalities
|
|
|
781
|
+ -- Prefer homogeneous equalities over hetero, because the
|
|
|
782
|
+ -- former might be holding up the latter.
|
|
|
783
|
+ -- See Note [Equalities with heterogeneous kinds] in GHC.Tc.Solver.Equality
|
|
|
784
|
+ , ("Homo eqs", is_homo_equality, True, mkGroupReporter mkEqErr)
|
|
|
785
|
+ , ("Other eqs", is_equality, True, mkGroupReporter mkEqErr)
|
|
|
786
|
+
|
|
|
787
|
+ , ("Insoluble fundeps", is_insoluble, True, mkGroupReporter mkDictErr)
|
|
|
788
|
+ ]
|
|
|
789
|
+
|
|
|
790
|
+ -- less_serious_reporters: we suppress these if have already
|
|
|
791
|
+ -- reported a serious error, higher in the tree
|
|
|
792
|
+ less_serious_reporters
|
|
|
793
|
+ = [ ("Irreds", is_irred, False, mkGroupReporter mkIrredErr)
|
|
|
794
|
+ , ("Dicts", is_dict, False, mkGroupReporter mkDictErr)
|
|
|
795
|
+ , ("Quantified", is_qc, False, mkGroupReporter mkQCErr) ]
|
|
801
|
796
|
|
|
802
|
797
|
-- rigid_nom_eq, rigid_nom_tv_eq,
|
|
803
|
798
|
is_dict, is_equality, is_FRR, is_irred :: ErrorItem -> Pred -> Bool
|
| ... |
... |
@@ -1310,14 +1305,16 @@ cmp_loc item1 item2 = get item1 `compare` get item2 |
|
1310
|
1305
|
|
|
1311
|
1306
|
reportGroup :: (NonEmpty ErrorItem -> TcM SolverReport) -> Reporter
|
|
1312
|
1307
|
reportGroup mk_err ctxt items
|
|
1313
|
|
- = do { err <- mk_err items
|
|
|
1308
|
+ = do { traceTc "reportGroup" (ppr items)
|
|
|
1309
|
+ ; err <- mk_err items
|
|
1314
|
1310
|
; traceTc "About to maybeReportErr" $
|
|
1315
|
1311
|
vcat [ text "Constraint:" <+> ppr items
|
|
1316
|
1312
|
, text "cec_suppress =" <+> ppr (cec_suppress ctxt)
|
|
1317
|
1313
|
, text "cec_defer_type_errors =" <+> ppr (cec_defer_type_errors ctxt) ]
|
|
|
1314
|
+
|
|
1318
|
1315
|
; maybeReportError ctxt items err
|
|
1319
|
1316
|
-- But see Note [Always warn with -fdefer-type-errors]
|
|
1320
|
|
- ; traceTc "reportGroup" (ppr items)
|
|
|
1317
|
+
|
|
1321
|
1318
|
; mapM_ (addSolverDeferredBinding err) items }
|
|
1322
|
1319
|
-- Add deferred bindings for all
|
|
1323
|
1320
|
-- Redundant if we are going to abort compilation,
|
| ... |
... |
@@ -1431,39 +1428,36 @@ mkErrorTerm ct_loc ty ctxt msg supp hints |
|
1431
|
1428
|
; return $ evDelayedError ty err_str }
|
|
1432
|
1429
|
|
|
1433
|
1430
|
tryReporters :: SolverReportErrCtxt -> [ReporterSpec] -> [ErrorItem]
|
|
1434
|
|
- -> TcM (SolverReportErrCtxt, [ErrorItem])
|
|
|
1431
|
+ -> TcM [ErrorItem]
|
|
1435
|
1432
|
-- Use the first reporter in the list whose predicate says True
|
|
1436
|
1433
|
tryReporters ctxt reporters items
|
|
1437
|
1434
|
= do { let (vis_items, invis_items) = partition (isVisibleOrigin . errorItemOrigin) items
|
|
1438
|
1435
|
; traceTc "tryReporters {" (ppr vis_items $$ ppr invis_items)
|
|
1439
|
|
- ; (ctxt', items') <- go ctxt reporters vis_items invis_items
|
|
|
1436
|
+ ; items' <- go reporters vis_items invis_items
|
|
1440
|
1437
|
; traceTc "tryReporters }" (ppr items')
|
|
1441
|
|
- ; return (ctxt', items') }
|
|
|
1438
|
+ ; return items' }
|
|
1442
|
1439
|
where
|
|
1443
|
|
- go ctxt [] vis_items invis_items
|
|
1444
|
|
- = return (ctxt, vis_items ++ invis_items)
|
|
|
1440
|
+ go [] vis_items invis_items
|
|
|
1441
|
+ = return (vis_items ++ invis_items)
|
|
1445
|
1442
|
|
|
1446
|
|
- go ctxt (r : rs) vis_items invis_items
|
|
|
1443
|
+ go (r : rs) vis_items invis_items
|
|
1447
|
1444
|
-- Always look at *visible* Origins before invisible ones
|
|
1448
|
1445
|
-- this is the whole point of isVisibleOrigin
|
|
1449
|
|
- = do { (ctxt', vis_items') <- tryReporter ctxt r vis_items
|
|
1450
|
|
- ; (ctxt'', invis_items') <- tryReporter ctxt' r invis_items
|
|
1451
|
|
- ; go ctxt'' rs vis_items' invis_items' }
|
|
|
1446
|
+ = do { vis_items' <- tryReporter ctxt r vis_items
|
|
|
1447
|
+ ; invis_items' <- tryReporter ctxt r invis_items
|
|
|
1448
|
+ ; go rs vis_items' invis_items' }
|
|
1452
|
1449
|
-- Carry on with the rest, because we must make
|
|
1453
|
1450
|
-- deferred bindings for them if we have -fdefer-type-errors
|
|
1454
|
1451
|
-- But suppress their error messages
|
|
1455
|
1452
|
|
|
1456
|
|
-tryReporter :: SolverReportErrCtxt -> ReporterSpec -> [ErrorItem] -> TcM (SolverReportErrCtxt, [ErrorItem])
|
|
1457
|
|
-tryReporter ctxt (str, keep_me, suppress_after, reporter) items = case nonEmpty yeses of
|
|
1458
|
|
- Nothing -> pure (ctxt, items)
|
|
|
1453
|
+tryReporter :: SolverReportErrCtxt -> ReporterSpec -> [ErrorItem] -> TcM [ErrorItem]
|
|
|
1454
|
+tryReporter ctxt (str, keep_me, _, reporter) items = case nonEmpty yeses of
|
|
|
1455
|
+ Nothing -> return items
|
|
1459
|
1456
|
Just yeses -> do
|
|
1460
|
1457
|
{ traceTc "tryReporter{ " (text str <+> ppr yeses)
|
|
1461
|
|
- ; (_, no_errs) <- askNoErrs (reporter ctxt yeses)
|
|
1462
|
|
- ; let suppress_now = not no_errs && suppress_after
|
|
1463
|
|
- -- See (SLIE2) in Note [cec_suppress: suppressing less-important error messages]
|
|
1464
|
|
- ctxt' = ctxt { cec_suppress = suppress_now || cec_suppress ctxt }
|
|
1465
|
|
- ; traceTc "tryReporter end }" (text str <+> ppr (cec_suppress ctxt) <+> ppr suppress_after <+> ppr (cec_suppress ctxt'))
|
|
1466
|
|
- ; return (ctxt', nos) }
|
|
|
1458
|
+ ; reporter ctxt yeses
|
|
|
1459
|
+ ; traceTc "tryReporter end }" empty
|
|
|
1460
|
+ ; return nos }
|
|
1467
|
1461
|
where
|
|
1468
|
1462
|
(yeses, nos) = partition keep items
|
|
1469
|
1463
|
keep item = keep_me item (classifyPredType (errorItemPred item))
|