Vladislav Zavialov pushed to branch wip/int-index/out-of-scope at Glasgow Haskell Compiler / GHC

Commits:

5 changed files:

Changes:

  • compiler/GHC/Tc/Errors.hs
    ... ... @@ -5,7 +5,7 @@
    5 5
     module GHC.Tc.Errors(
    
    6 6
            reportUnsolved, reportAllUnsolved, warnAllUnsolved,
    
    7 7
            warnDefaulting,
    
    8
    -       mkDelayedErrorTerm,
    
    8
    +       pprDeferredTypeError,
    
    9 9
     
    
    10 10
            -- * GHC API helper functions
    
    11 11
            solverReportMsg_ExpectedActuals, mismatchMsg_ExpectedActuals
    
    ... ... @@ -1387,19 +1387,15 @@ mkErrorTerm ct_loc ty ctxt msg supp hints
    1387 1387
                       supp
    
    1388 1388
                       hints
    
    1389 1389
              -- This will be reported at runtime, so we always want "error:" in the report, never "warning:"
    
    1390
    -       ; mkDelayedErrorTerm ty msg }
    
    1391
    -
    
    1392
    -mkDelayedErrorTerm
    
    1393
    -  :: Type -- of the error term
    
    1394
    -  -> MsgEnvelope TcRnMessage
    
    1395
    -  -> TcM EvTerm
    
    1396
    -mkDelayedErrorTerm ty msg
    
    1397
    -  = do { dflags <- getDynFlags
    
    1398
    -       ; let err_msg = pprLocMsgEnvelope (initTcMessageOpts dflags) msg
    
    1399
    -             err_str = showSDoc dflags $
    
    1400
    -                       err_msg $$ text "(deferred type error)"
    
    1401
    -
    
    1402
    -       ; return $ evDelayedError ty err_str }
    
    1390
    +       ; dflags <- getDynFlags
    
    1391
    +       ; let err_msg = pprDeferredTypeError dflags msg
    
    1392
    +       ; return $ evDelayedError ty err_msg }
    
    1393
    +
    
    1394
    +pprDeferredTypeError :: DynFlags -> MsgEnvelope TcRnMessage -> String
    
    1395
    +pprDeferredTypeError dflags msg =
    
    1396
    +  let err_msg = pprLocMsgEnvelope (initTcMessageOpts dflags) msg
    
    1397
    +  in showSDoc dflags $
    
    1398
    +     err_msg $$ text "(deferred type error)"
    
    1403 1399
     
    
    1404 1400
     tryReporters :: SolverReportErrCtxt -> [ReporterSpec] -> [ErrorItem] -> TcM (SolverReportErrCtxt, [ErrorItem])
    
    1405 1401
     -- Use the first reporter in the list whose predicate says True
    

  • compiler/GHC/Tc/Gen/Head.hs
    ... ... @@ -39,7 +39,7 @@ 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
    
    42
    +import GHC.Tc.Errors ( pprDeferredTypeError )
    
    43 43
     import GHC.Tc.Solver          ( InferMode(..), simplifyInfer )
    
    44 44
     import GHC.Tc.Utils.Env
    
    45 45
     import GHC.Tc.Utils.TcMType
    
    ... ... @@ -832,20 +832,18 @@ tc_infer_id (L loc qnm@(WithUserRdr rdr id_name))
    832 832
                      | otherwise = ErrorWithoutFlag
    
    833 833
           msg <- mk_msg reason
    
    834 834
           addDiagnosticTc msg
    
    835
    -      if defer_out_of_scope then msg_to_hole msg else failM
    
    835
    +      msg_to_hole msg
    
    836 836
     
    
    837 837
         msg_to_hole :: TcRnMessage -> TcM (HsExpr GhcTc, TcType)
    
    838 838
         msg_to_hole msg = do
    
    839
    -      loc <- getSrcSpanM
    
    840
    -      let locc = L (noAnnSrcSpan loc) rdr
    
    841
    -      ty <- newOpenFlexiTyVarTy
    
    842
    -      u <- newUnique
    
    843
    -      msg_envelope <- mkTcRnMessage loc msg
    
    844
    -      delayed_err <- mkDelayedErrorTerm ty msg_envelope
    
    845
    -      ref <- newTcRef delayed_err
    
    839
    +      dflags <- getDynFlags
    
    840
    +      let lrdr = L loc rdr
    
    841
    +      msg_envelope <- mkTcRnMessage (locA loc) msg
    
    842
    +      let err_msg = pprDeferredTypeError dflags msg_envelope
    
    843
    +      ty  <- newOpenFlexiTyVarTy
    
    844
    +      her <- newExprHoleRef ty (evDelayedError ty err_msg)
    
    846 845
           tcEmitBindingUsage bottomUE   -- Holes fit any usage environment (#18491)
    
    847
    -      let her = HER ref ty u
    
    848
    -      return (HsHole (HoleVar locc, her), ty)
    
    846
    +      return (HsHole (HoleVar lrdr, her), ty)
    
    849 847
     
    
    850 848
     {- Note [Overview of assertions]
    
    851 849
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

  • compiler/GHC/Tc/Utils/Env.hs
    ... ... @@ -402,7 +402,6 @@ mkIllegalTyVarMessage :: DiagnosticReason -> WithUserRdr Name -> TcM TcRnMessage
    402 402
         fail_with_msg :: DiagnosticReason -> WhatLooking -> NameSpace -> RdrName -> Name
    
    403 403
                       -> Maybe TermLevelUseCtxt -> TermLevelUseErr -> TcM TcRnMessage
    
    404 404
         fail_with_msg reason what_looking whatName rdr nm pprov err = do
    
    405
    -      -- defer_out_of_scope <- goptM Opt_DeferOutOfScopeVariables
    
    406 405
           (imp_errs, hints) <- get_suggestions what_looking whatName rdr
    
    407 406
           hfdc <- getHoleFitDispConfig
    
    408 407
           unit_state <- hsc_units <$> getTopEnv
    

  • compiler/GHC/Tc/Utils/TcMType.hs
    ... ... @@ -45,6 +45,8 @@ module GHC.Tc.Utils.TcMType (
    45 45
       emitWantedEqs, emitNewExprHole,
    
    46 46
       newTcEvBinds, newNoTcEvBinds, addTcEvBind,
    
    47 47
     
    
    48
    +  newExprHoleRef,
    
    49
    +
    
    48 50
       newCoercionHole, fillCoercionHole, isFilledCoercionHole,
    
    49 51
       checkCoercionHole,
    
    50 52
     
    
    ... ... @@ -314,6 +316,12 @@ emitNewExprHole occ ty
    314 316
            ; emitHole hole
    
    315 317
            ; return her }
    
    316 318
     
    
    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
    +
    
    317 325
     newDict :: Class -> [TcType] -> TcM DictId
    
    318 326
     newDict cls tys
    
    319 327
       = do { name <- newSysName (mkDictOcc (getOccName cls))
    

  • testsuite/tests/rename/should_fail/RnStaticPointersFail02.stderr
    1
    +RnStaticPointersFail02.hs:5:5: error: [GHC-39999]
    
    2
    +    • No instance for ‘ghc-internal-9.1500.0:GHC.Internal.Data.Typeable.Internal.Typeable
    
    3
    +                         t0’
    
    4
    +        arising from a static form
    
    5
    +    • In the expression: static T
    
    6
    +      In an equation for ‘f’: f = static T
    
    1 7
     
    
    2 8
     RnStaticPointersFail02.hs:5:12: error: [GHC-01928]
    
    3 9
         • Illegal term-level use of the type constructor ‘T’
    
    ... ... @@ -5,3 +11,4 @@ RnStaticPointersFail02.hs:5:12: error: [GHC-01928]
    5 11
         • In the body of a static form: T
    
    6 12
           In the expression: static T
    
    7 13
           In an equation for ‘f’: f = static T
    
    14
    +