Vladislav Zavialov pushed to branch wip/int-index/out-of-scope at Glasgow Haskell Compiler / GHC
Commits:
-
e8b37cc8
by Vladislav Zavialov at 2026-03-06T21:56:52+03:00
12 changed files:
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Hole.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- testsuite/tests/rename/should_compile/T19966.hs
- testsuite/tests/rename/should_compile/T19966.stderr
- testsuite/tests/rename/should_compile/T19966_main.stdout
Changes:
| ... | ... | @@ -28,14 +28,13 @@ import GHC.Tc.Errors.Ppr |
| 28 | 28 | import GHC.Tc.Types.Constraint
|
| 29 | 29 | import GHC.Tc.Types.CtLoc
|
| 30 | 30 | import GHC.Tc.Utils.TcMType
|
| 31 | -import GHC.Tc.Utils.Env (tcLookupId, tcLookupDataCon)
|
|
| 31 | +import GHC.Tc.Utils.Env
|
|
| 32 | 32 | import GHC.Tc.Zonk.Type
|
| 33 | 33 | import GHC.Tc.Utils.TcType
|
| 34 | 34 | import GHC.Tc.Zonk.TcType
|
| 35 | 35 | import GHC.Tc.Types.Origin
|
| 36 | 36 | import GHC.Tc.Types.Evidence
|
| 37 | 37 | import GHC.Tc.Instance.Family
|
| 38 | -import GHC.Tc.Utils.Instantiate
|
|
| 39 | 38 | import {-# SOURCE #-} GHC.Tc.Errors.Hole ( findValidHoleFits, getHoleFitDispConfig )
|
| 40 | 39 | |
| 41 | 40 | import GHC.Types.Name
|
| ... | ... | @@ -63,13 +62,14 @@ import GHC.Core.Class (className) |
| 63 | 62 | import GHC.Core.ConLike (isExistentialRecordField, ConLike (..))
|
| 64 | 63 | import GHC.Core.Coercion
|
| 65 | 64 | import GHC.Core.DataCon
|
| 65 | +import GHC.Core.TyCo.Rep
|
|
| 66 | 66 | import GHC.Core.TyCo.Ppr ( pprTyVars )
|
| 67 | 67 | import GHC.Core.TyCo.Tidy
|
| 68 | 68 | |
| 69 | 69 | import GHC.Core.InstEnv
|
| 70 | 70 | import GHC.Core.TyCon
|
| 71 | 71 | |
| 72 | -import GHC.Utils.Error (diagReasonSeverity)
|
|
| 72 | +import GHC.Utils.Error (diagReasonSeverity, pprLocMsgEnvelope )
|
|
| 73 | 73 | import GHC.Utils.Misc
|
| 74 | 74 | import GHC.Utils.Outputable as O
|
| 75 | 75 | import GHC.Utils.Panic
|
| ... | ... | @@ -1353,7 +1353,8 @@ addDeferredBinding ctxt supp hints msg (EI { ei_evdest = Just dest |
| 1353 | 1353 | , ei_loc = loc })
|
| 1354 | 1354 | -- if evdest is Just, then the constraint was from a wanted
|
| 1355 | 1355 | | deferringAnyBindings ctxt
|
| 1356 | - = do { err_tm <- mkErrorTerm loc item_ty ctxt msg supp hints
|
|
| 1356 | + = do { msg <- mkErrorReport (ctLocEnv loc) msg (Just ctxt) supp hints
|
|
| 1357 | + ; err_tm <- mkErrorTerm item_ty msg
|
|
| 1357 | 1358 | ; let ev_binds_var = cec_binds ctxt
|
| 1358 | 1359 | |
| 1359 | 1360 | ; case dest of
|
| ... | ... | @@ -1370,26 +1371,24 @@ addDeferredBinding _ _ _ _ _ = return () -- Do not set any evidence for Given |
| 1370 | 1371 | mkSolverErrorTerm :: CtLoc -> Type -- of the error term
|
| 1371 | 1372 | -> SolverReport -> TcM EvTerm
|
| 1372 | 1373 | mkSolverErrorTerm ct_loc ty err
|
| 1373 | - = mkErrorTerm ct_loc ty (reportContext . sr_important_msg $ err)
|
|
| 1374 | - (TcRnSolverReport (sr_important_msg err) ErrorWithoutFlag)
|
|
| 1375 | - (sr_supplementary err)
|
|
| 1376 | - (sr_hints err)
|
|
| 1377 | - |
|
| 1378 | -mkErrorTerm :: CtLoc -> Type -- of the error term
|
|
| 1379 | - -> SolverReportErrCtxt -> TcRnMessage
|
|
| 1380 | - -> [SupplementaryInfo] -> [GhcHint] -> TcM EvTerm
|
|
| 1381 | -mkErrorTerm ct_loc ty ctxt msg supp hints
|
|
| 1382 | 1374 | = do { msg <- mkErrorReport
|
| 1383 | 1375 | (ctLocEnv ct_loc)
|
| 1384 | - msg
|
|
| 1385 | - (Just $ ctxt)
|
|
| 1386 | - supp
|
|
| 1387 | - hints
|
|
| 1376 | + (TcRnSolverReport (sr_important_msg err) ErrorWithoutFlag)
|
|
| 1377 | + (Just $ reportContext $ sr_important_msg err)
|
|
| 1378 | + (sr_supplementary err)
|
|
| 1379 | + (sr_hints err)
|
|
| 1388 | 1380 | -- This will be reported at runtime, so we always want "error:" in the report, never "warning:"
|
| 1389 | - ; dflags <- getDynFlags
|
|
| 1390 | - ; let msg_opts = initTcMessageOpts dflags
|
|
| 1391 | - err_msg = showSDoc dflags $ pprDeferredTypeError msg_opts msg
|
|
| 1392 | - ; return $ evDelayedError ty err_msg }
|
|
| 1381 | + ; mkErrorTerm ty msg
|
|
| 1382 | + }
|
|
| 1383 | + |
|
| 1384 | +mkErrorTerm :: Type -> MsgEnvelope TcRnMessage -> TcM EvTerm
|
|
| 1385 | +mkErrorTerm ty msg =
|
|
| 1386 | + do { dflags <- getDynFlags
|
|
| 1387 | + ; let err_msg = pprLocMsgEnvelope (initTcMessageOpts dflags) msg
|
|
| 1388 | + err_str = showSDoc dflags $
|
|
| 1389 | + err_msg $$ text "(deferred type error)"
|
|
| 1390 | + |
|
| 1391 | + ; return $ evDelayedError ty err_str }
|
|
| 1393 | 1392 | |
| 1394 | 1393 | tryReporters :: SolverReportErrCtxt -> [ReporterSpec] -> [ErrorItem] -> TcM (SolverReportErrCtxt, [ErrorItem])
|
| 1395 | 1394 | -- Use the first reporter in the list whose predicate says True
|
| ... | ... | @@ -1551,6 +1550,22 @@ See also 'reportUnsolved'. |
| 1551 | 1550 | ----------------
|
| 1552 | 1551 | -- | Constructs a new hole error, unless this is deferred. See Note [Constructing Hole Errors].
|
| 1553 | 1552 | mkHoleError :: NameEnv Type -> [ErrorItem] -> SolverReportErrCtxt -> Hole -> TcM (MsgEnvelope TcRnMessage)
|
| 1553 | +mkHoleError _ _ ctxt hole
|
|
| 1554 | + | ExprHole (ExprHoleBoundToType t) (HER ref ref_ty _) <- hole_sort hole
|
|
| 1555 | + = setCtLocM (hole_loc hole) $
|
|
| 1556 | + do { let reason = cec_out_of_scope_holes ctxt
|
|
| 1557 | + ; msg <- case t of
|
|
| 1558 | + TyVarTy tv -> mkIllegalTyVarMessage reason (WithUserRdr rdr (tyVarName tv))
|
|
| 1559 | + TyConApp tc [] -> mkIllegalTyConMessage reason WL_Term (WithUserRdr rdr (tyConName tc))
|
|
| 1560 | + _ -> pprPanic "mkHoleError" (ppr t)
|
|
| 1561 | + ; msg <- mkErrorReport lcl_env msg (Just ctxt) [] noHints
|
|
| 1562 | + ; when (deferringAnyBindings ctxt) $ do
|
|
| 1563 | + err_tm <- mkErrorTerm ref_ty msg
|
|
| 1564 | + writeMutVar ref err_tm
|
|
| 1565 | + ; return msg }
|
|
| 1566 | + where
|
|
| 1567 | + rdr = hole_occ hole
|
|
| 1568 | + lcl_env = ctLocEnv (hole_loc hole)
|
|
| 1554 | 1569 | mkHoleError _ _tidy_simples ctxt hole@(Hole { hole_sort = sort, hole_occ = occ, hole_loc = ct_loc })
|
| 1555 | 1570 | | isOutOfScopeHole hole
|
| 1556 | 1571 | = do { (imp_errs, hints)
|
| ... | ... | @@ -1586,7 +1601,7 @@ mkHoleError lcl_name_cache tidy_simples ctxt |
| 1586 | 1601 | |
| 1587 | 1602 | ; show_hole_constraints <- goptM Opt_ShowHoleConstraints
|
| 1588 | 1603 | ; let relevant_cts
|
| 1589 | - | ExprHole _ <- sort, show_hole_constraints
|
|
| 1604 | + | ExprHole _ _ <- sort, show_hole_constraints
|
|
| 1590 | 1605 | = givenConstraints ctxt
|
| 1591 | 1606 | | otherwise
|
| 1592 | 1607 | = []
|
| ... | ... | @@ -1596,8 +1611,8 @@ mkHoleError lcl_name_cache tidy_simples ctxt |
| 1596 | 1611 | then validHoleFits ctxt tidy_simples hole
|
| 1597 | 1612 | else return (ctxt, noValidHoleFits)
|
| 1598 | 1613 | ; (grouped_skvs, other_tvs) <- liftZonkM $ zonkAndGroupSkolTvs hole_ty
|
| 1599 | - ; let reason | ExprHole _ <- sort = cec_expr_holes ctxt
|
|
| 1600 | - | otherwise = cec_type_holes ctxt
|
|
| 1614 | + ; let reason | ExprHole _ _ <- sort = cec_expr_holes ctxt
|
|
| 1615 | + | otherwise = cec_type_holes ctxt
|
|
| 1601 | 1616 | err = SolverReportWithCtxt ctxt
|
| 1602 | 1617 | $ ReportHoleError hole
|
| 1603 | 1618 | $ HoleError sort other_tvs grouped_skvs
|
| ... | ... | @@ -1650,7 +1665,7 @@ maybeAddDeferredBindings :: Hole |
| 1650 | 1665 | -> TcM ()
|
| 1651 | 1666 | maybeAddDeferredBindings hole report = do
|
| 1652 | 1667 | case hole_sort hole of
|
| 1653 | - ExprHole (HER ref ref_ty _) -> do
|
|
| 1668 | + ExprHole _ (HER ref ref_ty _) -> do
|
|
| 1654 | 1669 | -- Only add bindings for holes in expressions
|
| 1655 | 1670 | -- not for holes in partial type signatures
|
| 1656 | 1671 | -- cf. addDeferredBinding
|
| ... | ... | @@ -586,7 +586,7 @@ findValidHoleFits :: TidyEnv -- ^ The tidy_env for zonking |
| 586 | 586 | -- the hole.
|
| 587 | 587 | -> Hole
|
| 588 | 588 | -> TcM (TidyEnv, ValidHoleFits)
|
| 589 | -findValidHoleFits tidy_env implics simples h@(Hole { hole_sort = ExprHole _
|
|
| 589 | +findValidHoleFits tidy_env implics simples h@(Hole { hole_sort = ExprHole _ _
|
|
| 590 | 590 | , hole_loc = ct_loc
|
| 591 | 591 | , hole_ty = hole_ty }) =
|
| 592 | 592 | do { rdr_env <- getGlobalRdrEnv
|
| ... | ... | @@ -19,7 +19,6 @@ module GHC.Tc.Errors.Ppr |
| 19 | 19 | , TcRnMessageOpts(..)
|
| 20 | 20 | , pprTyThingUsedWrong
|
| 21 | 21 | , pprUntouchableVariable
|
| 22 | - , pprDeferredTypeError
|
|
| 23 | 22 | |
| 24 | 23 | --
|
| 25 | 24 | , mismatchMsg_ExpectedActuals
|
| ... | ... | @@ -124,7 +123,6 @@ import GHC.Utils.Lexeme |
| 124 | 123 | import GHC.Utils.Misc
|
| 125 | 124 | import GHC.Utils.Outputable
|
| 126 | 125 | import GHC.Utils.Panic
|
| 127 | -import GHC.Utils.Error
|
|
| 128 | 126 | |
| 129 | 127 | import qualified GHC.LanguageExtensions as LangExt
|
| 130 | 128 | |
| ... | ... | @@ -1151,7 +1149,7 @@ instance Diagnostic TcRnMessage where |
| 1151 | 1149 | -> mkSimpleDecorated $
|
| 1152 | 1150 | vcat [ text "The literal" <+> quotes (ppr lit) <+> text "cannot be promoted."
|
| 1153 | 1151 | , text "It is of the unpromotable type" <+> quotes (ppr (hsLitType lit)) <> dot ]
|
| 1154 | - TcRnIllegalTermLevelUse simple_msg _ rdr name err
|
|
| 1152 | + TcRnIllegalTermLevelUse simple_msg rdr name err _
|
|
| 1155 | 1153 | -> mkSimpleDecorated $
|
| 1156 | 1154 | if simple_msg
|
| 1157 | 1155 | then
|
| ... | ... | @@ -2380,8 +2378,8 @@ instance Diagnostic TcRnMessage where |
| 2380 | 2378 | -> ErrorWithoutFlag
|
| 2381 | 2379 | TcRnUnpromotableLit{}
|
| 2382 | 2380 | -> ErrorWithoutFlag
|
| 2383 | - TcRnIllegalTermLevelUse _ reason _ _ _
|
|
| 2384 | - -> reason -- Error, or a Warning if we are deferring type errors
|
|
| 2381 | + TcRnIllegalTermLevelUse _ _ _ _ reason
|
|
| 2382 | + -> reason
|
|
| 2385 | 2383 | TcRnMatchesHaveDiffNumArgs{}
|
| 2386 | 2384 | -> ErrorWithoutFlag
|
| 2387 | 2385 | TcRnCannotBindScopedTyVarInPatSig{}
|
| ... | ... | @@ -4462,11 +4460,6 @@ pprUntouchableVariable tv (Implic { ic_given = given, ic_info = skol_info, ic_en |
| 4462 | 4460 | , nest 2 $ text "bound by" <+> ppr skol_info
|
| 4463 | 4461 | , nest 2 $ text "at" <+> ppr (getCtLocEnvLoc env) ]
|
| 4464 | 4462 | |
| 4465 | -pprDeferredTypeError :: DiagnosticOpts TcRnMessage -> MsgEnvelope TcRnMessage -> SDoc
|
|
| 4466 | -pprDeferredTypeError opts msg =
|
|
| 4467 | - pprLocMsgEnvelope opts msg $$
|
|
| 4468 | - text "(deferred type error)"
|
|
| 4469 | - |
|
| 4470 | 4463 | -- | Which invisible bits of types should be displayed to the user when
|
| 4471 | 4464 | -- rendering a 'MismatchMsg'?
|
| 4472 | 4465 | --
|
| ... | ... | @@ -2495,11 +2495,10 @@ data TcRnMessage where |
| 2495 | 2495 | TcRnIllegalTermLevelUse
|
| 2496 | 2496 | :: !Bool -- ^ should we give a simple "out of scope" message,
|
| 2497 | 2497 | -- instead of a full-blown "Illegal term level use" message?
|
| 2498 | - |
|
| 2499 | - -> !DiagnosticReason
|
|
| 2500 | 2498 | -> !RdrName -- ^ the user-written identifier
|
| 2501 | 2499 | -> !Name -- ^ the type-level 'Name' we resolved it to
|
| 2502 | 2500 | -> !TermLevelUseErr
|
| 2501 | + -> !DiagnosticReason -- ^ Whether to defer this error or fail
|
|
| 2503 | 2502 | -> TcRnMessage
|
| 2504 | 2503 | |
| 2505 | 2504 | {-| TcRnMatchesHaveDiffNumArgs is an error occurring when something has matches
|
| ... | ... | @@ -5956,6 +5955,7 @@ data HoleError |
| 5956 | 5955 | --
|
| 5957 | 5956 | -- Test cases: T9177a.
|
| 5958 | 5957 | = OutOfScopeHole
|
| 5958 | + |
|
| 5959 | 5959 | -- | Report a typed hole, or wildcard, with additional information.
|
| 5960 | 5960 | | HoleError HoleSort
|
| 5961 | 5961 | [TcTyVar] -- Other type variables which get computed on the way.
|
| ... | ... | @@ -51,6 +51,7 @@ import GHC.Tc.Utils.Instantiate |
| 51 | 51 | import GHC.Tc.Utils.Env
|
| 52 | 52 | import GHC.Tc.Types.Origin
|
| 53 | 53 | import GHC.Tc.Types.Evidence
|
| 54 | +import GHC.Tc.Types.Constraint
|
|
| 54 | 55 | import GHC.Tc.Errors.Types hiding (HoleError)
|
| 55 | 56 | |
| 56 | 57 | import GHC.Core.Multiplicity
|
| ... | ... | @@ -322,9 +323,8 @@ tcExpr (XExpr e) res_ty = tcXExpr e res_ty |
| 322 | 323 | -- Others might simply be variables that accidentally have no binding site.
|
| 323 | 324 | tcExpr (HsHole (HoleVar locc@(L _ occ))) res_ty
|
| 324 | 325 | = do { ty <- expTypeToType res_ty -- Allow Int# etc (#12531)
|
| 325 | - ; her <- emitNewExprHole occ ty
|
|
| 326 | - ; tcEmitBindingUsage bottomUE -- Holes fit any usage environment
|
|
| 327 | - -- (#18491)
|
|
| 326 | + ; her <- emitNewExprHole ExprHoleUnbound occ ty
|
|
| 327 | + ; tcEmitBindingUsage bottomUE -- Holes fit any usage environment (#18491)
|
|
| 328 | 328 | ; return (HsHole (HoleVar locc, her))
|
| 329 | 329 | }
|
| 330 | 330 | tcExpr (HsHole HoleError) _ =
|
| ... | ... | @@ -39,12 +39,11 @@ import GHC.Tc.Utils.Unify |
| 39 | 39 | import GHC.Tc.Utils.Instantiate
|
| 40 | 40 | import GHC.Tc.Instance.Family ( tcLookupDataFamInst )
|
| 41 | 41 | import GHC.Tc.Errors.Types
|
| 42 | -import GHC.Tc.Errors.Ppr ( pprDeferredTypeError )
|
|
| 43 | 42 | import GHC.Tc.Solver ( InferMode(..), simplifyInfer )
|
| 44 | 43 | import GHC.Tc.Utils.Env
|
| 45 | 44 | import GHC.Tc.Utils.TcMType
|
| 46 | 45 | import GHC.Tc.Types.Origin
|
| 47 | -import GHC.Tc.Types.Constraint( WantedConstraints )
|
|
| 46 | +import GHC.Tc.Types.Constraint( WantedConstraints, ExprHoleVariant(..) )
|
|
| 48 | 47 | import GHC.Tc.Utils.TcType as TcType
|
| 49 | 48 | import GHC.Tc.Types.Evidence
|
| 50 | 49 | import GHC.Tc.Zonk.TcType
|
| ... | ... | @@ -68,8 +67,6 @@ import GHC.Types.Error |
| 68 | 67 | import GHC.Builtin.Names
|
| 69 | 68 | |
| 70 | 69 | import GHC.Driver.DynFlags
|
| 71 | -import GHC.Driver.Ppr (showSDoc)
|
|
| 72 | -import GHC.Driver.Config.Diagnostic (initTcMessageOpts)
|
|
| 73 | 70 | import GHC.Utils.Misc
|
| 74 | 71 | import GHC.Utils.Outputable as Outputable
|
| 75 | 72 | import GHC.Utils.Panic
|
| ... | ... | @@ -802,7 +799,7 @@ tcInferId lname@(L loc (WithUserRdr rdr id_name)) |
| 802 | 799 | = tc_infer_id lname
|
| 803 | 800 | |
| 804 | 801 | tc_infer_id :: LocatedN (WithUserRdr Name) -> TcM (HsExpr GhcTc, TcSigmaType)
|
| 805 | -tc_infer_id (L loc qnm@(WithUserRdr rdr id_name))
|
|
| 802 | +tc_infer_id (L loc (WithUserRdr rdr id_name))
|
|
| 806 | 803 | = do { thing <- tcLookup id_name
|
| 807 | 804 | ; (expr,ty) <- case thing of
|
| 808 | 805 | ATcId { tct_id = id }
|
| ... | ... | @@ -816,9 +813,8 @@ tc_infer_id (L loc qnm@(WithUserRdr rdr id_name)) |
| 816 | 813 | |
| 817 | 814 | AGlobal (AConLike cl) -> tcInferConLike cl
|
| 818 | 815 | |
| 819 | - (tcTyThingTyCon_maybe -> Just _)
|
|
| 820 | - -> defer_or_fail $ \reason -> mkIllegalTyConMessage reason WL_Term qnm
|
|
| 821 | - ATyVar _ _ -> defer_or_fail $ \reason -> mkIllegalTyVarMessage reason qnm
|
|
| 816 | + (tcTyThingTyCon_maybe -> Just tc) -> mk_hole (mkTyConTy tc)
|
|
| 817 | + ATyVar _ tv -> mk_hole (mkTyVarTy tv)
|
|
| 822 | 818 | |
| 823 | 819 | _ -> failWithTc $ TcRnExpectedValueId thing
|
| 824 | 820 | |
| ... | ... | @@ -827,26 +823,12 @@ tc_infer_id (L loc qnm@(WithUserRdr rdr id_name)) |
| 827 | 823 | where
|
| 828 | 824 | return_id id = return (mkHsVar (L loc id), idType id)
|
| 829 | 825 | |
| 830 | - defer_or_fail :: (DiagnosticReason -> TcM TcRnMessage) -> TcM (HsExpr GhcTc, TcSigmaType)
|
|
| 831 | - defer_or_fail mk_msg = do
|
|
| 832 | - defer_out_of_scope <- goptM Opt_DeferOutOfScopeVariables
|
|
| 833 | - let reason | defer_out_of_scope = WarningWithFlag Opt_WarnDeferredOutOfScopeVariables
|
|
| 834 | - | otherwise = ErrorWithoutFlag
|
|
| 835 | - msg <- mk_msg reason
|
|
| 836 | - addDiagnosticTc msg
|
|
| 837 | - msg_to_hole msg
|
|
| 838 | - |
|
| 839 | - msg_to_hole :: TcRnMessage -> TcM (HsExpr GhcTc, TcType)
|
|
| 840 | - msg_to_hole msg = do
|
|
| 841 | - dflags <- getDynFlags
|
|
| 842 | - let lrdr = L loc rdr
|
|
| 843 | - msg_envelope <- mkTcRnMessage (locA loc) msg
|
|
| 844 | - let msg_opts = initTcMessageOpts dflags
|
|
| 845 | - err_msg = showSDoc dflags $ pprDeferredTypeError msg_opts msg_envelope
|
|
| 846 | - ty <- newOpenFlexiTyVarTy
|
|
| 847 | - her <- newExprHoleRef ty (evDelayedError ty err_msg)
|
|
| 848 | - tcEmitBindingUsage bottomUE -- Holes fit any usage environment (#18491)
|
|
| 849 | - return (HsHole (HoleVar lrdr, her), ty)
|
|
| 826 | + mk_hole :: TcType -> TcM (HsExpr GhcTc, TcSigmaType)
|
|
| 827 | + mk_hole ty
|
|
| 828 | + = do { hole_ty <- newOpenFlexiTyVarTy
|
|
| 829 | + ; her <- emitNewExprHole (ExprHoleBoundToType ty) rdr hole_ty
|
|
| 830 | + ; tcEmitBindingUsage bottomUE -- Holes fit any usage environment (#18491)
|
|
| 831 | + ; return (HsHole (HoleVar (L loc rdr), her), hole_ty) }
|
|
| 850 | 832 | |
| 851 | 833 | {- Note [Overview of assertions]
|
| 852 | 834 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -50,6 +50,7 @@ module GHC.Tc.Types.Constraint ( |
| 50 | 50 | |
| 51 | 51 | -- Holes
|
| 52 | 52 | Hole(..), HoleSort(..), isOutOfScopeHole,
|
| 53 | + ExprHoleVariant(..),
|
|
| 53 | 54 | DelayedError(..), NotConcreteError(..),
|
| 54 | 55 | |
| 55 | 56 | WantedConstraints(..), insolubleWC, emptyWC, isEmptyWC,
|
| ... | ... | @@ -409,9 +410,12 @@ data Hole |
| 409 | 410 | -- might get reported to the user if reducing type families in a
|
| 410 | 411 | -- hole type loops.
|
| 411 | 412 | |
| 413 | +data ExprHoleVariant
|
|
| 414 | + = ExprHoleUnbound
|
|
| 415 | + | ExprHoleBoundToType TcType
|
|
| 412 | 416 | |
| 413 | 417 | -- | Used to indicate which sort of hole we have.
|
| 414 | -data HoleSort = ExprHole HoleExprRef
|
|
| 418 | +data HoleSort = ExprHole ExprHoleVariant HoleExprRef
|
|
| 415 | 419 | -- ^ Either an out-of-scope variable or a "true" hole in an
|
| 416 | 420 | -- expression (TypedHoles).
|
| 417 | 421 | -- The HoleExprRef says where to write the
|
| ... | ... | @@ -425,7 +429,7 @@ data HoleSort = ExprHole HoleExprRef |
| 425 | 429 | -- Note [Do not simplify ConstraintHoles] in GHC.Tc.Solver.
|
| 426 | 430 | |
| 427 | 431 | instance Outputable Hole where
|
| 428 | - ppr (Hole { hole_sort = ExprHole ref
|
|
| 432 | + ppr (Hole { hole_sort = ExprHole _ ref
|
|
| 429 | 433 | , hole_occ = occ
|
| 430 | 434 | , hole_ty = ty })
|
| 431 | 435 | = parens $ (braces $ ppr occ <> colon <> ppr ref) <+> dcolon <+> ppr ty
|
| ... | ... | @@ -435,9 +439,9 @@ instance Outputable Hole where |
| 435 | 439 | = braces $ ppr occ <> colon <> ppr ty
|
| 436 | 440 | |
| 437 | 441 | instance Outputable HoleSort where
|
| 438 | - ppr (ExprHole ref) = text "ExprHole:" <+> ppr ref
|
|
| 439 | - ppr TypeHole = text "TypeHole"
|
|
| 440 | - ppr ConstraintHole = text "ConstraintHole"
|
|
| 442 | + ppr (ExprHole _ ref) = text "ExprHole:" <+> ppr ref
|
|
| 443 | + ppr TypeHole = text "TypeHole"
|
|
| 444 | + ppr ConstraintHole = text "ConstraintHole"
|
|
| 441 | 445 | |
| 442 | 446 | -- | Why did we require that a certain type be concrete?
|
| 443 | 447 | data NotConcreteError
|
| ... | ... | @@ -399,15 +399,13 @@ mkIllegalTyVarMessage :: DiagnosticReason -> WithUserRdr Name -> TcM TcRnMessage |
| 399 | 399 | fail_tyvar reason (WithUserRdr rdr nm) =
|
| 400 | 400 | fail_with_msg reason WL_Term varName rdr nm (Just TermLevelUseTyVar) TyVarTE
|
| 401 | 401 | |
| 402 | - fail_with_msg :: DiagnosticReason -> WhatLooking -> NameSpace -> RdrName -> Name
|
|
| 403 | - -> Maybe TermLevelUseCtxt -> TermLevelUseErr -> TcM TcRnMessage
|
|
| 404 | 402 | fail_with_msg reason what_looking whatName rdr nm pprov err = do
|
| 405 | 403 | (imp_errs, hints) <- get_suggestions what_looking whatName rdr
|
| 406 | 404 | hfdc <- getHoleFitDispConfig
|
| 407 | 405 | unit_state <- hsc_units <$> getTopEnv
|
| 408 | 406 | let
|
| 409 | 407 | want_simple = want_simple_msg hints
|
| 410 | - msg = TcRnIllegalTermLevelUse want_simple reason rdr nm err
|
|
| 408 | + msg = TcRnIllegalTermLevelUse want_simple rdr nm err reason
|
|
| 411 | 409 | info = ErrInfo { errInfoContext =
|
| 412 | 410 | if want_simple
|
| 413 | 411 | then []
|
| ... | ... | @@ -417,8 +415,7 @@ mkIllegalTyVarMessage :: DiagnosticReason -> WithUserRdr Name -> TcM TcRnMessage |
| 417 | 415 | NE.nonEmpty imp_errs
|
| 418 | 416 | , errInfoHints = hints
|
| 419 | 417 | }
|
| 420 | - msg_w_info = TcRnMessageWithInfo unit_state (mkDetailedMessage info msg)
|
|
| 421 | - return msg_w_info
|
|
| 418 | + return $ TcRnMessageWithInfo unit_state (mkDetailedMessage info msg)
|
|
| 422 | 419 | |
| 423 | 420 | get_suggestions what_looking ns rdr = do
|
| 424 | 421 | required_type_arguments <- xoptM LangExt.RequiredTypeArguments
|
| ... | ... | @@ -45,8 +45,6 @@ module GHC.Tc.Utils.TcMType ( |
| 45 | 45 | emitWantedEqs, emitNewExprHole,
|
| 46 | 46 | newTcEvBinds, newNoTcEvBinds, addTcEvBind,
|
| 47 | 47 | |
| 48 | - newExprHoleRef,
|
|
| 49 | - |
|
| 50 | 48 | newCoercionHole, fillCoercionHole, isFilledCoercionHole,
|
| 51 | 49 | checkCoercionHole,
|
| 52 | 50 | |
| ... | ... | @@ -300,28 +298,23 @@ emitWantedEvVar origin ty |
| 300 | 298 | ; return new_cv }
|
| 301 | 299 | |
| 302 | 300 | -- | Emit a new wanted expression hole
|
| 303 | -emitNewExprHole :: RdrName -- of the hole
|
|
| 301 | +emitNewExprHole :: ExprHoleVariant
|
|
| 302 | + -> RdrName -- of the hole
|
|
| 304 | 303 | -> Type -> TcM HoleExprRef
|
| 305 | -emitNewExprHole occ ty
|
|
| 304 | +emitNewExprHole variant occ ty
|
|
| 306 | 305 | = do { u <- newUnique
|
| 307 | 306 | ; ref <- newTcRef (pprPanic "unfilled unbound-variable evidence" (ppr u))
|
| 308 | 307 | ; let her = HER ref ty u
|
| 309 | 308 | |
| 310 | 309 | ; loc <- getCtLocM (ExprHoleOrigin (Just occ)) (Just TypeLevel)
|
| 311 | 310 | |
| 312 | - ; let hole = Hole { hole_sort = ExprHole her
|
|
| 311 | + ; let hole = Hole { hole_sort = ExprHole variant her
|
|
| 313 | 312 | , hole_occ = occ
|
| 314 | 313 | , hole_ty = ty
|
| 315 | 314 | , hole_loc = loc }
|
| 316 | 315 | ; emitHole hole
|
| 317 | 316 | ; return her }
|
| 318 | 317 | |
| 319 | -newExprHoleRef :: Type -> EvTerm -> TcM HoleExprRef
|
|
| 320 | -newExprHoleRef ty ev
|
|
| 321 | - = do { u <- newUnique
|
|
| 322 | - ; ref <- newTcRef ev
|
|
| 323 | - ; return $ HER ref ty u }
|
|
| 324 | - |
|
| 325 | 318 | newDict :: Class -> [TcType] -> TcM DictId
|
| 326 | 319 | newDict cls tys
|
| 327 | 320 | = do { name <- newSysName (mkDictOcc (getOccName cls))
|
| ... | ... | @@ -3,7 +3,6 @@ |
| 3 | 3 | |
| 4 | 4 | module T19966 where
|
| 5 | 5 | |
| 6 | -import Control.Exception (evaluate)
|
|
| 7 | 6 | import Data.Proxy
|
| 8 | 7 | |
| 9 | 8 | -- "I" is out of scope, but we accept the definition
|
| 1 | -T19966.hs:11:7: warning: [GHC-88464] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 1 | +T19966.hs:10:7: warning: [GHC-88464] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 2 | 2 | Data constructor not in scope: I
|
| 3 | 3 | |
| 4 | -T19966.hs:18:7: warning: [GHC-01928] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 4 | +T19966.hs:17:7: warning: [GHC-01928] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 5 | 5 | • Data constructor out of scope: ‘Bool’.
|
| 6 | 6 | NB: the type constructor ‘Bool’ cannot appear in this position.
|
| 7 | 7 | • In the expression: Bool
|
| 8 | 8 | In an equation for ‘ex2’: ex2 = Bool
|
| 9 | - Suggested fix: Perhaps use ‘Boo1’ (line 21)
|
|
| 9 | + Suggested fix: Perhaps use ‘Boo1’ (line 20)
|
|
| 10 | 10 | |
| 11 | -T19966.hs:29:13: warning: [GHC-01928] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 11 | +T19966.hs:28:13: warning: [GHC-01928] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 12 | 12 | • Illegal term-level use of the type variable ‘a’
|
| 13 | - • bound at T19966.hs:28:15
|
|
| 13 | + • bound at T19966.hs:27:1
|
|
| 14 | 14 | • In the first argument of ‘not’, namely ‘a’
|
| 15 | 15 | In the expression: not a
|
| 16 | 16 | In an equation for ‘ex3’: ex3 _ = not a
|
| 1 | -T19966.hs:11:7: error: [GHC-88464]
|
|
| 1 | +T19966.hs:10:7: error: [GHC-88464]
|
|
| 2 | 2 | • Data constructor not in scope: I
|
| 3 | 3 | • In an equation for ‘ex1’: ex1 = I
|
| 4 | 4 | (deferred type error)
|
| 5 | -T19966.hs:18:7: warning: [GHC-01928] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 6 | - Data constructor out of scope: ‘Bool’.
|
|
| 7 | - NB: the type constructor ‘Bool’ cannot appear in this position.
|
|
| 5 | +T19966.hs:17:7: warning: [GHC-01928] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 6 | + • Data constructor out of scope: ‘Bool’.
|
|
| 7 | + NB: the type constructor ‘Bool’ cannot appear in this position.
|
|
| 8 | + • In the expression: Bool
|
|
| 9 | + In an equation for ‘ex2’: ex2 = Bool
|
|
| 8 | 10 | (deferred type error)
|
| 9 | -T19966.hs:29:13: warning: [GHC-01928] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 11 | +T19966.hs:28:13: warning: [GHC-01928] [-Wdeferred-out-of-scope-variables (in -Wdefault)]
|
|
| 10 | 12 | • Illegal term-level use of the type variable ‘a’
|
| 11 | - • bound at T19966.hs:28:15
|
|
| 13 | + • bound at T19966.hs:27:1
|
|
| 14 | + • In the first argument of ‘not’, namely ‘a’
|
|
| 15 | + In the expression: not a
|
|
| 16 | + In an equation for ‘ex3’: ex3 _ = not a
|
|
| 12 | 17 | (deferred type error) |