Apoorv Ingle pushed to branch wip/spj-apporv-Oct24 at Glasgow Haskell Compiler / GHC

Commits:

18 changed files:

Changes:

  • compiler/GHC/Hs/Expr.hs
    ... ... @@ -676,22 +676,22 @@ data SrcCodeOrigin
    676 676
       = OrigExpr (HsExpr GhcRn)                -- ^ The source, user written, expression
    
    677 677
       | OrigStmt (ExprLStmt GhcRn) HsDoFlavour -- ^ which kind of do-block did this statement come from
    
    678 678
       | OrigPat  (Pat GhcRn)                   -- ^ Used for failable patterns that trigger MonadFail constraints
    
    679
    +  | PopErrCtxt -- A hint for typechecker to pop
    
    680
    +               -- the top of the error context stack
    
    681
    +               -- Does not presist post renaming phase
    
    682
    +               -- See Part 3. of Note [Expanding HsDo with XXExprGhcRn]
    
    683
    +               -- in `GHC.Tc.Gen.Do`
    
    684
    +               -- INVARIANT: SHOULD NEVER APPEAR IN A ExpansionCodeCtxt in CodeSrcFlag ErrCtxt on stack
    
    679 685
     
    
    680 686
     data XXExprGhcRn
    
    681 687
       = ExpandedThingRn { xrn_orig     :: SrcCodeOrigin   -- The original source thing to be used for error messages
    
    682 688
                         , xrn_expanded :: HsExpr GhcRn    -- The compiler generated, expanded thing
    
    683 689
                         }
    
    684 690
     
    
    685
    -  | PopErrCtxt                                     -- A hint for typechecker to pop
    
    686
    -    {-# UNPACK #-} !(HsExpr GhcRn)                 -- the top of the error context stack
    
    687
    -                                                   -- Does not presist post renaming phase
    
    688
    -                                                   -- See Part 3. of Note [Expanding HsDo with XXExprGhcRn]
    
    689
    -                                                   -- in `GHC.Tc.Gen.Do`
    
    690 691
       | HsRecSelRn  (FieldOcc GhcRn)   -- ^ Variable pointing to record selector
    
    691 692
                                -- See Note [Non-overloaded record field selectors] and
    
    692 693
                                -- Note [Record selectors in the AST]
    
    693 694
     
    
    694
    -
    
    695 695
     -- | Build an expression using the extension constructor `XExpr`,
    
    696 696
     --   and the two components of the expansion: original expression and
    
    697 697
     --   expanded expressions.
    
    ... ... @@ -713,6 +713,12 @@ mkExpandedStmt
    713 713
     mkExpandedStmt oStmt flav eExpr = XExpr (ExpandedThingRn { xrn_orig = OrigStmt oStmt flav
    
    714 714
                                                              , xrn_expanded = eExpr })
    
    715 715
     
    
    716
    +mkExpandedLastStmt
    
    717
    +  :: HsExpr GhcRn         -- ^ expanded expression
    
    718
    +  -> HsExpr GhcRn         -- ^ suitably wrapped 'XXExprGhcRn'
    
    719
    +mkExpandedLastStmt eExpr = XExpr (ExpandedThingRn { xrn_orig = PopErrCtxt
    
    720
    +                                                  , xrn_expanded = eExpr })
    
    721
    +
    
    716 722
     data XXExprGhcTc
    
    717 723
       = WrapExpr        -- Type and evidence application and abstractions
    
    718 724
           HsWrapper (HsExpr GhcTc)
    
    ... ... @@ -1083,11 +1089,11 @@ instance Outputable SrcCodeOrigin where
    1083 1089
             OrigExpr x    -> ppr_builder "<OrigExpr>:" x
    
    1084 1090
             OrigStmt x _  -> ppr_builder "<OrigStmt>:" x
    
    1085 1091
             OrigPat  x    -> ppr_builder "<OrigPat>:" x
    
    1092
    +        PopErrCtxt    -> text "<PopErrCtxt>"
    
    1086 1093
         where ppr_builder prefix x = ifPprDebug (braces (text prefix <+> parens (ppr x))) (ppr x)
    
    1087 1094
     
    
    1088 1095
     instance Outputable XXExprGhcRn where
    
    1089 1096
       ppr (ExpandedThingRn o e) = ifPprDebug (braces $ vcat [ppr o, text ";;" , ppr e]) (ppr o)
    
    1090
    -  ppr (PopErrCtxt e)        = ifPprDebug (braces (text "<PopErrCtxt>" <+> ppr e)) (ppr e)
    
    1091 1097
       ppr (HsRecSelRn f)        = pprPrefixOcc f
    
    1092 1098
     
    
    1093 1099
     instance Outputable XXExprGhcTc where
    
    ... ... @@ -1133,7 +1139,6 @@ ppr_infix_expr _ = Nothing
    1133 1139
     
    
    1134 1140
     ppr_infix_expr_rn :: XXExprGhcRn -> Maybe SDoc
    
    1135 1141
     ppr_infix_expr_rn (ExpandedThingRn thing _) = ppr_infix_hs_expansion thing
    
    1136
    -ppr_infix_expr_rn (PopErrCtxt a)            = ppr_infix_expr a
    
    1137 1142
     ppr_infix_expr_rn (HsRecSelRn f)            = Just (pprInfixOcc f)
    
    1138 1143
     
    
    1139 1144
     ppr_infix_expr_tc :: XXExprGhcTc -> Maybe SDoc
    
    ... ... @@ -1233,7 +1238,6 @@ hsExprNeedsParens prec = go
    1233 1238
     
    
    1234 1239
         go_x_rn :: XXExprGhcRn -> Bool
    
    1235 1240
         go_x_rn (ExpandedThingRn thing _ )   = hsExpandedNeedsParens thing
    
    1236
    -    go_x_rn (PopErrCtxt a)               = hsExprNeedsParens prec a
    
    1237 1241
         go_x_rn (HsRecSelRn{})               = False
    
    1238 1242
     
    
    1239 1243
         hsExpandedNeedsParens :: SrcCodeOrigin -> Bool
    
    ... ... @@ -1286,7 +1290,6 @@ isAtomicHsExpr (XExpr x)
    1286 1290
     
    
    1287 1291
         go_x_rn :: XXExprGhcRn -> Bool
    
    1288 1292
         go_x_rn (ExpandedThingRn thing _)   = isAtomicExpandedThingRn thing
    
    1289
    -    go_x_rn (PopErrCtxt a)              = isAtomicHsExpr a
    
    1290 1293
         go_x_rn (HsRecSelRn{})              = True
    
    1291 1294
     
    
    1292 1295
         isAtomicExpandedThingRn :: SrcCodeOrigin -> Bool
    

  • compiler/GHC/HsToCore/Quote.hs
    ... ... @@ -1744,7 +1744,6 @@ repE e@(XExpr (ExpandedThingRn o x))
    1744 1744
              else repE e }
    
    1745 1745
       | otherwise
    
    1746 1746
       = notHandled (ThExpressionForm e)
    
    1747
    -repE (XExpr (PopErrCtxt e)) = repE e
    
    1748 1747
     repE (XExpr (HsRecSelRn (FieldOcc _ (L _ x)))) = repE (mkHsVar (noLocA x))
    
    1749 1748
     repE e@(HsPragE _ (HsPragSCC {}) _) = notHandled (ThCostCentres e)
    
    1750 1749
     repE e@(HsTypedBracket{})   = notHandled (ThExpressionForm e)
    

  • compiler/GHC/Rename/Utils.hs
    ... ... @@ -20,7 +20,7 @@ module GHC.Rename.Utils (
    20 20
             DeprecationWarnings(..), warnIfDeprecated,
    
    21 21
             checkUnusedRecordWildcard,
    
    22 22
             badQualBndrErr, typeAppErr, badFieldConErr,
    
    23
    -        wrapGenSpan, genHsVar, genLHsVar, genHsApp, genHsApps, genHsApps', genHsExpApps,
    
    23
    +        wrapGenSpan, wrapNoSpan, genHsVar, genLHsVar, genHsApp, genHsApps, genHsApps', genHsExpApps,
    
    24 24
             genLHsApp, genAppType,
    
    25 25
             genLHsLit, genHsIntegralLit, genHsTyLit, genSimpleConPat,
    
    26 26
             genVarPat, genWildPat,
    
    ... ... @@ -705,6 +705,12 @@ wrapGenSpan :: (HasAnnotation an) => a -> GenLocated an a
    705 705
     -- See Note [Rebindable syntax and XXExprGhcRn]
    
    706 706
     wrapGenSpan x = L (noAnnSrcSpan generatedSrcSpan) x
    
    707 707
     
    
    708
    +wrapNoSpan :: (HasAnnotation an) => a -> GenLocated an a
    
    709
    +-- Wrap something in a "noSrcSpan"
    
    710
    +-- See Note [Rebindable syntax and XXExprGhcRn]
    
    711
    +wrapNoSpan x = L (noAnnSrcSpan noSrcSpan) x
    
    712
    +
    
    713
    +
    
    708 714
     -- | Make a 'SyntaxExpr' from a 'Name' (the "rn" is because this is used in the
    
    709 715
     -- renamer).
    
    710 716
     mkRnSyntaxExpr :: Name -> SyntaxExprRn
    

  • compiler/GHC/Tc/Errors.hs
    ... ... @@ -26,10 +26,6 @@ import GHC.Driver.Config.Diagnostic
    26 26
     
    
    27 27
     import GHC.Rename.Unbound
    
    28 28
     
    
    29
    -import Language.Haskell.Syntax (DotFieldOcc (..))
    
    30
    -import Language.Haskell.Syntax.Basic (FieldLabelString (..))
    
    31
    -import GHC.Hs.Expr (SrcCodeOrigin (..), HsExpr (..))
    
    32
    -
    
    33 29
     import GHC.Tc.Types
    
    34 30
     import GHC.Tc.Utils.Monad
    
    35 31
     import GHC.Tc.Errors.Types
    
    ... ... @@ -2394,43 +2390,6 @@ mk_dict_err ctxt (item, (matches, pot_unifiers, unsafe_overlapped))
    2394 2390
             in different_names && same_occ_names
    
    2395 2391
           | otherwise = False
    
    2396 2392
     
    
    2397
    -    -- See Note [Out-of-scope fields with -XOverloadedRecordDot]
    
    2398
    -    record_field_suggestions :: ErrorItem -> TcM ([ImportError], [GhcHint])
    
    2399
    -    record_field_suggestions item = flip (maybe $ return ([], noHints)) record_field $ \name ->
    
    2400
    -       do { glb_env <- getGlobalRdrEnv
    
    2401
    -          ; lcl_env <- getLocalRdrEnv
    
    2402
    -          ; let field_name_hints = report_no_fieldnames item
    
    2403
    -          ; (errs, hints) <- if occ_name_in_scope glb_env lcl_env name
    
    2404
    -              then return ([], noHints)
    
    2405
    -              else unknownNameSuggestions emptyLocalRdrEnv WL_RecField (mkRdrUnqual name)
    
    2406
    -          ; pure (errs, hints ++ field_name_hints)
    
    2407
    -          }
    
    2408
    -
    
    2409
    -    -- get type names from instance
    
    2410
    -    -- resolve the type - if it's in scope is it a record?
    
    2411
    -    -- if it's a record, report an error - the record name + the field that could not be found
    
    2412
    -    report_no_fieldnames :: ErrorItem -> [GhcHint]
    
    2413
    -    report_no_fieldnames item
    
    2414
    -       | Just (EvVarDest evvar) <- ei_evdest item
    
    2415
    -       -- we can assume that here we have a `HasField @Symbol x r a` instance
    
    2416
    -       -- because of GetFieldOrigin in record_field
    
    2417
    -       , Just (_, [_symbol, x, r, a]) <- tcSplitTyConApp_maybe (varType evvar)
    
    2418
    -       , Just (r_tycon, _) <- tcSplitTyConApp_maybe r
    
    2419
    -       , Just x_name <- isStrLitTy x
    
    2420
    -       -- we check that this is a record type by checking whether it has any
    
    2421
    -       -- fields (in scope)
    
    2422
    -       , not . null $ tyConFieldLabels r_tycon
    
    2423
    -       = [RemindRecordMissingField x_name r a]
    
    2424
    -       | otherwise = []
    
    2425
    -
    
    2426
    -    occ_name_in_scope glb_env lcl_env occ_name = not $
    
    2427
    -      null (lookupGRE glb_env (LookupOccName occ_name (RelevantGREsFOS WantNormal))) &&
    
    2428
    -      isNothing (lookupLocalRdrOcc lcl_env occ_name)
    
    2429
    -
    
    2430
    -    record_field = case orig of
    
    2431
    -      ExpansionOrigin (OrigExpr (HsGetField _ _ (L _ name))) -> Just (mkVarOccFS (field_label $ unLoc $ dfoLabel name))
    
    2432
    -      _                   -> Nothing
    
    2433
    -
    
    2434 2393
     {- Note [Report candidate instances]
    
    2435 2394
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    2436 2395
     If we have an unsolved (Num Int), where `Int` is not the Prelude Int,
    

  • compiler/GHC/Tc/Errors/Ppr.hs
    ... ... @@ -7564,10 +7564,6 @@ pprTyConInstFlavour
    7564 7564
     pprErrCtxtMsg :: ErrCtxtMsg -> SDoc
    
    7565 7565
     pprErrCtxtMsg = \case
    
    7566 7566
       ExprCtxt expr
    
    7567
    -    | XExpr (ExpandedThingRn (OrigStmt (L _ stmt) flav) _) <- expr
    
    7568
    -    -> hang (text "In a stmt of" <+> pprAStmtContext @(LIdP GhcRn) (HsDoStmt flav) <> colon)
    
    7569
    -       2 (ppr_stmt stmt)
    
    7570
    -    | otherwise
    
    7571 7567
         -> hang (text "In the expression:")
    
    7572 7568
            2 (ppr (stripParensHsExpr expr))
    
    7573 7569
       ThetaCtxt ctxt theta ->
    

  • compiler/GHC/Tc/Gen/App.hs
    ... ... @@ -32,7 +32,8 @@ import GHC.Tc.Gen.HsType
    32 32
     import GHC.Tc.Utils.Concrete  ( unifyConcrete, idConcreteTvs )
    
    33 33
     import GHC.Tc.Utils.TcMType
    
    34 34
     import GHC.Tc.Types.Evidence
    
    35
    -import GHC.Tc.Types.ErrCtxt ( FunAppCtxtFunArg(..) )
    
    35
    +import GHC.Tc.Types.ErrCtxt ( FunAppCtxtFunArg(..), ErrCtxt (..),  CodeSrcFlag (..))
    
    36
    +import GHC.Tc.Errors.Ppr (pprErrCtxtMsg)
    
    36 37
     import GHC.Tc.Types.Origin
    
    37 38
     import GHC.Tc.Utils.TcType as TcType
    
    38 39
     import GHC.Tc.Utils.Concrete( hasFixedRuntimeRep_syntactic )
    
    ... ... @@ -173,6 +174,9 @@ Note [Instantiation variables are short lived]
    173 174
     -- CAUTION: Any changes to tcApp should be reflected here
    
    174 175
     -- cf. T19167. the head is an expanded expression applied to a type
    
    175 176
     -- TODO: Use runInfer for tcExprSigma?
    
    177
    +-- Caution: Currently we assume that the expression is compiler generated/expanded
    
    178
    +-- Becuase that is that T19167 testcase generates. This function can possibly
    
    179
    +-- take in the rn_expr and its location to pass into tcValArgs
    
    176 180
     tcExprSigma :: Bool -> HsExpr GhcRn -> TcM (HsExpr GhcTc, TcSigmaType)
    
    177 181
     tcExprSigma inst rn_expr
    
    178 182
       = do { (fun@(rn_fun,fun_ctxt), rn_args) <- splitHsApps rn_expr
    
    ... ... @@ -181,7 +185,7 @@ tcExprSigma inst rn_expr
    181 185
            ; code_orig <- getSrcCodeOrigin
    
    182 186
            ; let fun_orig = srcCodeOriginCtOrigin rn_expr code_orig
    
    183 187
            ; (inst_args, app_res_sigma) <- tcInstFun do_ql inst fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    
    184
    -       ; tc_args <- tcValArgs do_ql rn_fun inst_args
    
    188
    +       ; tc_args <- tcValArgs do_ql (rn_fun, generatedSrcSpan) inst_args
    
    185 189
            ; let tc_expr = rebuildHsApps (tc_fun, fun_ctxt) tc_args
    
    186 190
            ; return (tc_expr, app_res_sigma) }
    
    187 191
     
    
    ... ... @@ -394,16 +398,18 @@ tcApp :: HsExpr GhcRn
    394 398
     -- See Note [tcApp: typechecking applications]
    
    395 399
     tcApp rn_expr exp_res_ty
    
    396 400
       = do { -- Step 1: Split the application chain
    
    397
    -         (fun@(rn_fun, fun_loc), rn_args) <- splitHsApps rn_expr
    
    401
    +         (fun@(rn_fun, fun_lspan), rn_args) <- splitHsApps rn_expr
    
    402
    +       ; inGenCode <- inGeneratedCode
    
    398 403
            ; traceTc "tcApp {" $
    
    399
    -           vcat [ text "rn_expr:" <+> ppr rn_expr
    
    404
    +           vcat [ text "generated? " <+> ppr inGenCode
    
    405
    +                , text "rn_expr:" <+> ppr rn_expr
    
    400 406
                     , text "rn_fun:" <+> ppr rn_fun
    
    401
    -                , text "fun_loc:" <+> ppr fun_loc
    
    407
    +                , text "fun_lspan:" <+> ppr fun_lspan
    
    402 408
                     , text "rn_args:" <+> ppr rn_args ]
    
    403 409
     
    
    404 410
            -- Step 2: Infer the type of `fun`, the head of the application
    
    405 411
            ; (tc_fun, fun_sigma) <- tcInferAppHead fun
    
    406
    -       ; let tc_head = (tc_fun, fun_loc)
    
    412
    +       ; let tc_head = (tc_fun, fun_lspan)
    
    407 413
                  -- inst_final: top-instantiate the result type of the application,
    
    408 414
                  -- EXCEPT if we are trying to infer a sigma-type
    
    409 415
                  inst_final = case exp_res_ty of
    
    ... ... @@ -434,7 +440,7 @@ tcApp rn_expr exp_res_ty
    434 440
                   , text "fun_origin" <+> ppr fun_orig
    
    435 441
                   , text "do_ql:" <+> ppr do_ql]
    
    436 442
            ; (inst_args, app_res_rho)
    
    437
    -              <- tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_loc) fun_sigma rn_args
    
    443
    +              <- tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
    
    438 444
              -- See (TCAPP1) and (TCAPP2) in
    
    439 445
              -- Note [tcApp: typechecking applications]
    
    440 446
     
    
    ... ... @@ -447,7 +453,7 @@ tcApp rn_expr exp_res_ty
    447 453
                                                        app_res_rho exp_res_ty
    
    448 454
     
    
    449 455
                              -- Step 4.2: typecheck the  arguments
    
    450
    -                       ; tc_args <- tcValArgs NoQL rn_fun inst_args
    
    456
    +                       ; tc_args <- tcValArgs NoQL (rn_fun, fun_lspan) inst_args
    
    451 457
                              -- Step 4.3: wrap up
    
    452 458
                            ; finishApp tc_head tc_args app_res_rho res_wrap }
    
    453 459
     
    
    ... ... @@ -458,7 +464,7 @@ tcApp rn_expr exp_res_ty
    458 464
     
    
    459 465
                              -- Step 5.2: typecheck the arguments, and monomorphise
    
    460 466
                              --           any un-unified instantiation variables
    
    461
    -                       ; tc_args <- tcValArgs DoQL rn_fun inst_args
    
    467
    +                       ; tc_args <- tcValArgs DoQL (rn_fun, fun_lspan) inst_args
    
    462 468
                              -- Step 5.3: zonk to expose the polymorphism hidden under
    
    463 469
                              --           QuickLook instantiation variables in `app_res_rho`
    
    464 470
                            ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
    
    ... ... @@ -545,16 +551,16 @@ checkResultTy rn_expr (tc_fun, fun_loc) inst_args app_res_rho (Check res_ty)
    545 551
             thing_inside
    
    546 552
     
    
    547 553
     ----------------
    
    548
    -tcValArgs :: QLFlag -> HsExpr GhcRn -> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
    
    554
    +tcValArgs :: QLFlag -> (HsExpr GhcRn, SrcSpan) -> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
    
    549 555
     -- Importantly, tcValArgs works left-to-right, so that by the time we
    
    550 556
     -- encounter an argument, we have monomorphised all the instantiation
    
    551 557
     -- variables that its type contains.  All that is left to do is an ordinary
    
    552 558
     -- zonkTcType.  See Note [Monomorphise instantiation variables].
    
    553
    -tcValArgs do_ql fun args = go do_ql 0 args
    
    559
    +tcValArgs do_ql (fun, fun_lspan) args = go do_ql 0 args
    
    554 560
       where
    
    555 561
         go _ _ [] = return []
    
    556 562
         go do_ql pos (arg : args) =
    
    557
    -      do { arg' <- tcValArg do_ql pos' fun arg
    
    563
    +      do { arg' <- tcValArg do_ql pos' (fun, fun_lspan) arg
    
    558 564
              ; args' <- go do_ql pos' args
    
    559 565
              ; return (arg' : args') }
    
    560 566
           where
    
    ... ... @@ -570,7 +576,7 @@ tcValArgs do_ql fun args = go do_ql 0 args
    570 576
                  = pos
    
    571 577
     
    
    572 578
     
    
    573
    -tcValArg :: QLFlag -> Int -> HsExpr GhcRn -> HsExprArg 'TcpInst    -- Actual argument
    
    579
    +tcValArg :: QLFlag -> Int -> (HsExpr GhcRn, SrcSpan) -> HsExprArg 'TcpInst    -- Actual argument
    
    574 580
              -> TcM (HsExprArg 'TcpTc)          -- Resulting argument
    
    575 581
     tcValArg _     _ _ (EPrag l p)         = return (EPrag l (tcExprPrag p))
    
    576 582
     tcValArg _     _ _ (ETypeArg l hty ty) = return (ETypeArg l hty ty)
    
    ... ... @@ -579,10 +585,10 @@ tcValArg do_ql _ _ (EWrap (EHsWrap w)) = do { whenQL do_ql $ qlMonoHsWrapper w
    579 585
       -- qlMonoHsWrapper: see Note [Monomorphise instantiation variables]
    
    580 586
     tcValArg _     _ _ (EWrap ew)          = return (EWrap ew)
    
    581 587
     
    
    582
    -tcValArg do_ql pos fun (EValArg { ea_loc_span   = ctxt
    
    588
    +tcValArg do_ql pos (fun, fun_lspan) (EValArg { ea_loc_span  = lspan
    
    583 589
                                 , ea_arg    = larg@(L arg_loc arg)
    
    584 590
                                 , ea_arg_ty = sc_arg_ty })
    
    585
    -  = addArgCtxt pos fun larg $
    
    591
    +  = addArgCtxt pos (fun, fun_lspan) larg $
    
    586 592
         do { -- Crucial step: expose QL results before checking exp_arg_ty
    
    587 593
              -- So far as the paper is concerned, this step applies
    
    588 594
              -- the poly-substitution Theta, learned by QL, so that we
    
    ... ... @@ -596,7 +602,8 @@ tcValArg do_ql pos fun (EValArg { ea_loc_span = ctxt
    596 602
                   DoQL -> liftZonkM $ zonkScaledTcType sc_arg_ty
    
    597 603
                   NoQL -> return sc_arg_ty
    
    598 604
            ; traceTc "tcValArg {" $
    
    599
    -         vcat [ text "ctxt:" <+> ppr ctxt
    
    605
    +         vcat [ text "lspan:" <+> ppr lspan
    
    606
    +              , text "fun_lspan" <+> ppr fun_lspan
    
    600 607
                   , text "sigma_type" <+> ppr (mkCheckExpType exp_arg_ty)
    
    601 608
                   , text "arg:" <+> ppr larg
    
    602 609
                   ]
    
    ... ... @@ -607,13 +614,13 @@ tcValArg do_ql pos fun (EValArg { ea_loc_span = ctxt
    607 614
                      tcPolyExpr arg (mkCheckExpType exp_arg_ty)
    
    608 615
            ; traceTc "tcValArg" $ vcat [ ppr arg'
    
    609 616
                                        , text "}" ]
    
    610
    -       ; return (EValArg { ea_loc_span = ctxt
    
    617
    +       ; return (EValArg { ea_loc_span = lspan
    
    611 618
                              , ea_arg = L arg_loc arg'
    
    612 619
                              , ea_arg_ty = noExtField }) }
    
    613 620
     
    
    614
    -tcValArg _ pos fun (EValArgQL {
    
    621
    +tcValArg _ pos (fun, fun_lspan) (EValArgQL {
    
    615 622
                             eaql_wanted   = wanted
    
    616
    -                      , eaql_loc_span = ctxt
    
    623
    +                      , eaql_loc_span = lspan
    
    617 624
                           , eaql_arg_ty   = sc_arg_ty
    
    618 625
                           , eaql_larg     = larg@(L arg_loc rn_expr)
    
    619 626
                           , eaql_tc_fun   = tc_head
    
    ... ... @@ -622,7 +629,7 @@ tcValArg _ pos fun (EValArgQL {
    622 629
                           , eaql_args     = inst_args
    
    623 630
                           , eaql_encl     = arg_influences_enclosing_call
    
    624 631
                           , eaql_res_rho  = app_res_rho })
    
    625
    -  = addArgCtxt pos fun larg $
    
    632
    +  = addArgCtxt pos (fun, fun_lspan) larg $
    
    626 633
         do { -- Expose QL results to tcSkolemise, as in EValArg case
    
    627 634
              Scaled mult exp_arg_ty <- liftZonkM $ zonkScaledTcType sc_arg_ty
    
    628 635
     
    
    ... ... @@ -631,6 +638,8 @@ tcValArg _ pos fun (EValArgQL {
    631 638
                                            , text "args:" <+> ppr inst_args
    
    632 639
                                            , text "mult:" <+> ppr mult
    
    633 640
                                            , text "fun" <+> ppr fun
    
    641
    +                                       , text "app_lspan" <+> ppr lspan
    
    642
    +                                       , text "head_lspan" <+> ppr fun_lspan
    
    634 643
                                            , text "tc_head" <+> ppr tc_head])
    
    635 644
     
    
    636 645
            ; ds_flag <- getDeepSubsumptionFlag
    
    ... ... @@ -649,7 +658,7 @@ tcValArg _ pos fun (EValArgQL {
    649 658
                       ; unless arg_influences_enclosing_call $  -- Don't repeat
    
    650 659
                         qlUnify app_res_rho exp_arg_rho         -- the qlUnify
    
    651 660
     
    
    652
    -                  ; tc_args <- tcValArgs DoQL rn_fun inst_args
    
    661
    +                  ; tc_args <- tcValArgs DoQL (rn_fun, snd tc_head) inst_args
    
    653 662
                       ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
    
    654 663
                       ; res_wrap <- checkResultTy rn_expr tc_head inst_args
    
    655 664
                                                   app_res_rho (mkCheckExpType exp_arg_rho)
    
    ... ... @@ -658,7 +667,7 @@ tcValArg _ pos fun (EValArgQL {
    658 667
            ; traceTc "tcEValArgQL }" $
    
    659 668
                vcat [ text "app_res_rho:" <+> ppr app_res_rho ]
    
    660 669
     
    
    661
    -       ; return (EValArg { ea_loc_span   = ctxt
    
    670
    +       ; return (EValArg { ea_loc_span   = lspan
    
    662 671
                              , ea_arg    = L arg_loc (mkHsWrap wrap arg')
    
    663 672
                              , ea_arg_ty = noExtField }) }
    
    664 673
     
    
    ... ... @@ -692,20 +701,20 @@ tcInstFun :: QLFlag
    692 701
                         -- Generally speaking we pass in True; in Fig 5 of the paper
    
    693 702
                         --    |-inst returns a rho-type
    
    694 703
               -> CtOrigin
    
    695
    -          -> (HsExpr GhcTc, HsExpr GhcRn, SrcSpan)
    
    704
    +          -> (HsExpr GhcTc, HsExpr GhcRn, SrcSpan) -- ANI: TODO, move HsExpr GhcRn, SrcSpan to CtOrigin
    
    696 705
               -> TcSigmaType -> [HsExprArg 'TcpRn]
    
    697 706
               -> TcM ( [HsExprArg 'TcpInst]
    
    698 707
                      , TcSigmaType )   -- Does not instantiate trailing invisible foralls
    
    699 708
     -- This crucial function implements the |-inst judgement in Fig 4, plus the
    
    700 709
     -- modification in Fig 5, of the QL paper:
    
    701 710
     -- "A quick look at impredicativity" (ICFP'20).
    
    702
    -tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    
    711
    +tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
    
    703 712
       = do { traceTc "tcInstFun" (vcat [ text "origin" <+> ppr fun_orig
    
    704 713
                                        , text "tc_fun" <+> ppr tc_fun
    
    705 714
                                        , text "fun_sigma" <+> ppr fun_sigma
    
    706 715
                                        , text "args:" <+> ppr rn_args
    
    707 716
                                        , text "do_ql" <+> ppr do_ql
    
    708
    -                                   , text "ctx" <+> ppr fun_ctxt])
    
    717
    +                                   , text "ctx" <+> ppr fun_lspan])
    
    709 718
            ; setQLInstLevel do_ql $  -- See (TCAPP1) and (TCAPP2) in
    
    710 719
                                      -- Note [tcApp: typechecking applications]
    
    711 720
                      go 1 [] fun_sigma rn_args }
    
    ... ... @@ -782,7 +791,7 @@ tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    782 791
           = do { (_inst_tvs, wrap, fun_rho) <-
    
    783 792
                     -- addHeadCtxt: important for the class constraints
    
    784 793
                     -- that may be emitted from instantiating fun_sigma
    
    785
    -                setSrcSpan fun_ctxt $
    
    794
    +                setSrcSpan fun_lspan $
    
    786 795
                     instantiateSigma fun_orig fun_conc_tvs tvs theta body2
    
    787 796
                       -- See Note [Representation-polymorphism checking built-ins]
    
    788 797
                       -- in GHC.Tc.Utils.Concrete.
    
    ... ... @@ -877,7 +886,7 @@ tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    877 886
                       (Just $ HsExprTcThing tc_fun)
    
    878 887
                       (n_val_args, fun_sigma) fun_ty
    
    879 888
     
    
    880
    -           ; arg' <- quickLookArg do_ql pos ctxt rn_fun arg arg_ty
    
    889
    +           ; arg' <- quickLookArg do_ql pos ctxt (rn_fun, fun_lspan) arg arg_ty
    
    881 890
                ; let acc' = arg' : addArgWrap wrap acc
    
    882 891
                ; go (pos+1) acc' res_ty rest_args }
    
    883 892
     
    
    ... ... @@ -927,28 +936,48 @@ looks_like_type_arg EValArg{ ea_arg = L _ e } =
    927 936
         _           -> False
    
    928 937
     looks_like_type_arg _ = False
    
    929 938
     
    
    930
    -addArgCtxt :: Int -> HsExpr GhcRn -> LHsExpr GhcRn
    
    939
    +addArgCtxt :: Int -> (HsExpr GhcRn, SrcSpan) -> LHsExpr GhcRn
    
    931 940
                -> TcM a -> TcM a
    
    932 941
     -- There are 2 cases:
    
    933
    --- 1. In the normal case, we add an informative context
    
    934
    ---          "In the third argument of f, namely blah"
    
    935
    --- 2. If we are deep inside generated code (<=> `isGeneratedCode` is `True`)
    
    936
    ---          "In the expression: arg"
    
    937
    ---  If the arg is also a generated thing, i.e. `arg_loc` is `generatedSrcSpan`, we would print nothing.
    
    942
    +-- 1. In the normal case, we add an informative context (<=> `inGeneratedCode` is `False`)
    
    943
    +--     "In the third argument of f, namely blah"
    
    944
    +-- 2. If we are inside generated code (<=> `inGeneratedCode` is `True`)
    
    945
    +--    (i)   If arg_loc is generated do nothing to to LclEnv/LclCtxt
    
    946
    +--    (ii)  If arg_loc is Unhelpful UnhelpfulNoLocationInfo set `tcl_in_gen_code` to `True`
    
    947
    +--    (iii) if arg_loc is RealSrcLoc then update tcl_loc and add "In the expression: arg" to ErrCtxtStack
    
    938 948
     --  See Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr
    
    939 949
     --  See Note [Expanding HsDo with XXExprGhcRn] in GHC.Tc.Gen.Do
    
    940
    -addArgCtxt arg_no fun (L arg_loc arg) thing_inside
    
    950
    +addArgCtxt arg_no (fun, fun_lspan) (L arg_loc arg) thing_inside
    
    941 951
       = do { in_generated_code <- inGeneratedCode
    
    952
    +       ; err_ctx <- getErrCtxt
    
    953
    +       ; env0 <- liftZonkM tcInitTidyEnv
    
    954
    +       ; err_ctx_msg <- mkErrCtxt env0 err_ctx
    
    942 955
            ; traceTc "addArgCtxt" (vcat [ text "generated:" <+> ppr in_generated_code
    
    943
    -                                    , text "arg: " <+> ppr arg
    
    944
    -                                    , text "arg_loc" <+> ppr arg_loc])
    
    945
    -       ; if in_generated_code
    
    946
    -         then do setSrcSpanA arg_loc $
    
    947
    -                   addExprCtxt arg     $  -- Auto-suppressed if arg_loc is generated
    
    948
    -                   thing_inside
    
    949
    -         else do setSrcSpanA arg_loc                    $
    
    950
    -                   addErrCtxt (FunAppCtxt (FunAppCtxtExpr fun arg) arg_no) $
    
    951
    -                   thing_inside }
    
    956
    +                                    , text "arg: " <+> ppr (arg, arg_no)
    
    957
    +                                    , text "arg_loc:" <+> ppr arg_loc
    
    958
    +                                    , text "fun:" <+> ppr fun
    
    959
    +                                    , text "fun_lspan" <+> ppr fun_lspan
    
    960
    +                                    , text "err_ctx" <+> vcat (fmap (\ (x, y) ->
    
    961
    +                                                         case x of
    
    962
    +                                                           MkErrCtxt (ExpansionCodeCtxt{}) _ -> text "<EXPN>" <+> pprErrCtxtMsg y
    
    963
    +                                                           _ -> text "<USER>" <+> pprErrCtxtMsg y)
    
    964
    +                                                                   (take 4 (zip err_ctx err_ctx_msg)))
    
    965
    +                                    ])
    
    966
    +       ; if not (isGeneratedSrcSpan fun_lspan)
    
    967
    +         then setSrcSpanA arg_loc                    $
    
    968
    +                 addErrCtxt (FunAppCtxt (FunAppCtxtExpr fun arg) arg_no) $
    
    969
    +                 thing_inside
    
    970
    +         else updCtxtForArg (L arg_loc arg) $
    
    971
    +                 thing_inside
    
    972
    + }
    
    973
    +  where
    
    974
    +    updCtxtForArg :: LHsExpr GhcRn -> TcRn a -> TcRn a
    
    975
    +    updCtxtForArg e@(L lspan _) thing_inside
    
    976
    +      = do setSrcSpan (locA lspan) $
    
    977
    +             addLExprCtxt e $ -- addLExpr is no op for non-user located exprs
    
    978
    +             thing_inside
    
    979
    +
    
    980
    +
    
    952 981
     
    
    953 982
     {- *********************************************************************
    
    954 983
     *                                                                      *
    
    ... ... @@ -1724,24 +1753,26 @@ This turned out to be more subtle than I expected. Wrinkles:
    1724 1753
     
    
    1725 1754
     -}
    
    1726 1755
     
    
    1727
    -quickLookArg :: QLFlag -> Int -> SrcSpan -> HsExpr GhcRn
    
    1756
    +quickLookArg :: QLFlag -> Int
    
    1757
    +             -> SrcSpan -- ^ location span of the whole application
    
    1758
    +             -> (HsExpr GhcRn, SrcSpan) -- ^ Head of the application chain and its source span
    
    1728 1759
                  -> LHsExpr GhcRn          -- ^ Argument
    
    1729 1760
                  -> Scaled TcSigmaTypeFRR  -- ^ Type expected by the function
    
    1730 1761
                  -> TcM (HsExprArg 'TcpInst)
    
    1731 1762
     -- See Note [Quick Look at value arguments]
    
    1732
    -quickLookArg NoQL _ ctxt _ larg orig_arg_ty
    
    1733
    -  = skipQuickLook ctxt larg orig_arg_ty
    
    1734
    -quickLookArg DoQL pos ctxt fun larg orig_arg_ty
    
    1763
    +quickLookArg NoQL _ app_lspan _ larg orig_arg_ty
    
    1764
    +  = skipQuickLook app_lspan larg orig_arg_ty
    
    1765
    +quickLookArg DoQL pos app_lspan fun_and_lspan larg orig_arg_ty
    
    1735 1766
       = do { is_rho <- tcIsDeepRho (scaledThing orig_arg_ty)
    
    1736 1767
            ; traceTc "qla" (ppr orig_arg_ty $$ ppr is_rho)
    
    1737 1768
            ; if not is_rho
    
    1738
    -         then skipQuickLook ctxt larg orig_arg_ty
    
    1739
    -         else quickLookArg1 pos ctxt fun larg orig_arg_ty }
    
    1769
    +         then skipQuickLook app_lspan larg orig_arg_ty
    
    1770
    +         else quickLookArg1 pos app_lspan fun_and_lspan larg orig_arg_ty }
    
    1740 1771
     
    
    1741 1772
     skipQuickLook :: SrcSpan -> LHsExpr GhcRn -> Scaled TcRhoType
    
    1742 1773
                   -> TcM (HsExprArg 'TcpInst)
    
    1743
    -skipQuickLook ctxt larg arg_ty
    
    1744
    -  = return (EValArg { ea_loc_span   = ctxt
    
    1774
    +skipQuickLook app_lspan larg arg_ty
    
    1775
    +  = return (EValArg { ea_loc_span   = app_lspan
    
    1745 1776
                         , ea_arg    = larg
    
    1746 1777
                         , ea_arg_ty = arg_ty })
    
    1747 1778
     
    
    ... ... @@ -1779,14 +1810,14 @@ isGuardedTy ty
    1779 1810
       | Just {} <- tcSplitAppTy_maybe ty        = True
    
    1780 1811
       | otherwise                               = False
    
    1781 1812
     
    
    1782
    -quickLookArg1 :: Int -> SrcSpan -> HsExpr GhcRn -> LHsExpr GhcRn
    
    1813
    +quickLookArg1 :: Int -> SrcSpan -> (HsExpr GhcRn, SrcSpan) -> LHsExpr GhcRn
    
    1783 1814
                   -> Scaled TcRhoType  -- Deeply skolemised
    
    1784 1815
                   -> TcM (HsExprArg 'TcpInst)
    
    1785 1816
     -- quickLookArg1 implements the "QL Argument" judgement in Fig 5 of the paper
    
    1786
    -quickLookArg1 pos ctxt fun larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
    
    1787
    -  = addArgCtxt pos fun larg $ -- Context needed for constraints
    
    1817
    +quickLookArg1 pos app_lspan (fun, fun_lspan) larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
    
    1818
    +  = addArgCtxt pos (fun, fun_lspan) larg $ -- Context needed for constraints
    
    1788 1819
                                -- generated by calls in arg
    
    1789
    -    do { ((rn_fun, fun_ctxt), rn_args) <- splitHsApps arg
    
    1820
    +    do { ((rn_fun, fun_lspan), rn_args) <- splitHsApps arg
    
    1790 1821
     
    
    1791 1822
            -- Step 1: get the type of the head of the argument
    
    1792 1823
            ; (fun_ue, mb_fun_ty) <- tcCollectingUsage $ tcInferAppHead_maybe rn_fun
    
    ... ... @@ -1802,15 +1833,15 @@ quickLookArg1 pos ctxt fun larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
    1802 1833
                   , text "args:" <+> ppr rn_args ]
    
    1803 1834
     
    
    1804 1835
            ; case mb_fun_ty of {
    
    1805
    -           Nothing -> skipQuickLook ctxt larg sc_arg_ty ;    -- fun is too complicated
    
    1836
    +           Nothing -> skipQuickLook app_lspan larg sc_arg_ty ;    -- fun is too complicated
    
    1806 1837
                Just (tc_fun, fun_sigma) ->
    
    1807 1838
     
    
    1808 1839
            -- step 2: use |-inst to instantiate the head applied to the arguments
    
    1809
    -    do { let tc_head = (tc_fun, fun_ctxt)
    
    1840
    +    do { let tc_head = (tc_fun, fun_lspan)
    
    1810 1841
            ; do_ql <- wantQuickLook rn_fun
    
    1811 1842
            ; ((inst_args, app_res_rho), wanted)
    
    1812 1843
                  <- captureConstraints $
    
    1813
    -                tcInstFun do_ql True (exprCtOrigin arg) (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
    
    1844
    +                tcInstFun do_ql True (exprCtOrigin arg) (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
    
    1814 1845
                     -- We must capture type-class and equality constraints here, but
    
    1815 1846
                     -- not equality constraints.  See (QLA6) in Note [Quick Look at
    
    1816 1847
                     -- value arguments]
    
    ... ... @@ -1842,7 +1873,7 @@ quickLookArg1 pos ctxt fun larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
    1842 1873
     
    
    1843 1874
            ; traceTc "quickLookArg done }" (ppr rn_fun)
    
    1844 1875
     
    
    1845
    -       ; return (EValArgQL { eaql_loc_span = ctxt
    
    1876
    +       ; return (EValArgQL { eaql_loc_span = app_lspan
    
    1846 1877
                                , eaql_arg_ty   = sc_arg_ty
    
    1847 1878
                                , eaql_larg     = larg
    
    1848 1879
                                , eaql_tc_fun   = tc_head
    

  • compiler/GHC/Tc/Gen/Do.hs
    ... ... @@ -97,7 +97,7 @@ expand_do_stmts doFlavour (stmt@(L loc (LetStmt _ bs)) : lstmts) =
    97 97
     --    ------------------------------------------------
    
    98 98
     --       let x = e ; stmts ~~> let x = e in stmts'
    
    99 99
       do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
    
    100
    -     let expansion = genHsLet bs (genPopErrCtxtExpr expand_stmts_expr)
    
    100
    +     let expansion = genHsLet bs expand_stmts_expr
    
    101 101
          return $ L loc (mkExpandedStmt stmt doFlavour expansion)
    
    102 102
     
    
    103 103
     expand_do_stmts doFlavour (stmt@(L loc (BindStmt xbsrn pat e)): lstmts)
    
    ... ... @@ -110,15 +110,15 @@ expand_do_stmts doFlavour (stmt@(L loc (BindStmt xbsrn pat e)): lstmts)
    110 110
     --    -------------------------------------------------------
    
    111 111
     --       pat <- e ; stmts   ~~> (>>=) e f
    
    112 112
       = do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
    
    113
    -       failable_expr <- mk_failable_expr doFlavour pat (genPopErrCtxtExpr expand_stmts_expr) fail_op
    
    113
    +       failable_expr <- mk_failable_expr doFlavour pat expand_stmts_expr fail_op
    
    114 114
            let expansion = genHsExpApps bind_op  -- (>>=)
    
    115
    -                       [ genPopErrCtxtExpr e
    
    115
    +                       [ e
    
    116 116
                            , failable_expr ]
    
    117 117
            return $ L loc (mkExpandedStmt stmt doFlavour expansion)
    
    118 118
       | otherwise
    
    119 119
       = pprPanic "expand_do_stmts: The impossible happened, missing bind operator from renamer" (text "stmt" <+> ppr  stmt)
    
    120 120
     
    
    121
    -expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ e (SyntaxExprRn then_op) _)) : lstmts) =
    
    121
    +expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ (L e_lspan e) (SyntaxExprRn then_op) _)) : lstmts) =
    
    122 122
     -- See Note [BodyStmt] in Language.Haskell.Syntax.Expr
    
    123 123
     -- See  Note [Expanding HsDo with XXExprGhcRn] Equation (1) below
    
    124 124
     --              stmts ~~> stmts'
    
    ... ... @@ -126,8 +126,8 @@ expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ e (SyntaxExprRn then_op) _))
    126 126
     --      e ; stmts ~~> (>>) e stmts'
    
    127 127
       do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
    
    128 128
          let expansion = genHsExpApps then_op  -- (>>)
    
    129
    -                     [ genPopErrCtxtExpr e
    
    130
    -                     , genPopErrCtxtExpr $ expand_stmts_expr ]
    
    129
    +                     [ L e_lspan (mkExpandedStmt stmt doFlavour e)
    
    130
    +                     , expand_stmts_expr ]
    
    131 131
          return $ L loc (mkExpandedStmt stmt doFlavour expansion)
    
    132 132
     
    
    133 133
     expand_do_stmts doFlavour
    
    ... ... @@ -484,12 +484,5 @@ It stores the original statement (with location) and the expanded expression
    484 484
     -}
    
    485 485
     
    
    486 486
     
    
    487
    --- | Wrap a located expression with a `PopErrCtxt`
    
    488
    -mkPopErrCtxtExpr :: HsExpr GhcRn -> HsExpr GhcRn
    
    489
    -mkPopErrCtxtExpr a = XExpr (PopErrCtxt a)
    
    490
    -
    
    491
    -genPopErrCtxtExpr :: LHsExpr GhcRn -> LHsExpr GhcRn
    
    492
    -genPopErrCtxtExpr (L loc a) = L loc (mkPopErrCtxtExpr a)
    
    493
    -
    
    494 487
     mkExpandedPatRn :: Pat GhcRn -> HsExpr GhcRn -> HsExpr GhcRn
    
    495 488
     mkExpandedPatRn pat e = XExpr (ExpandedThingRn (OrigPat pat) e)

  • compiler/GHC/Tc/Gen/Expr.hs
    ... ... @@ -122,7 +122,7 @@ tcPolyLExpr, tcPolyLExprNC :: LHsExpr GhcRn -> ExpSigmaType
    122 122
     
    
    123 123
     tcPolyLExpr (L loc expr) res_ty
    
    124 124
       = setSrcSpanA loc  $  -- Set location /first/; see GHC.Tc.Utils.Monad
    
    125
    -    addExprCtxt expr $  -- Note [Error contexts in generated code]
    
    125
    +    addLExprCtxt (L loc expr) $  -- Note [Error contexts in generated code]
    
    126 126
         do { expr' <- tcPolyExpr expr res_ty
    
    127 127
            ; return (L loc expr') }
    
    128 128
     
    
    ... ... @@ -241,7 +241,7 @@ tcInferRhoNC = tcInferExprNC IIF_DeepRho
    241 241
     tcInferExpr, tcInferExprNC :: InferInstFlag -> LHsExpr GhcRn -> TcM (LHsExpr GhcTc, TcType)
    
    242 242
     tcInferExpr iif (L loc expr)
    
    243 243
       = setSrcSpanA loc  $  -- Set location /first/; see GHC.Tc.Utils.Monad
    
    244
    -    addExprCtxt expr $  -- Note [Error contexts in generated code]
    
    244
    +    addLExprCtxt (L loc expr) $  -- Note [Error contexts in generated code]
    
    245 245
         do { (expr', rho) <- runInfer iif IFRR_Any (tcExpr expr)
    
    246 246
            ; return (L loc expr', rho) }
    
    247 247
     
    
    ... ... @@ -268,7 +268,7 @@ tcMonoLExpr, tcMonoLExprNC
    268 268
     
    
    269 269
     tcMonoLExpr (L loc expr) res_ty
    
    270 270
       = setSrcSpanA loc   $  -- Set location /first/; see GHC.Tc.Utils.Monad
    
    271
    -    addExprCtxt expr $  -- Note [Error contexts in generated code]
    
    271
    +    addLExprCtxt (L loc expr) $  -- Note [Error contexts in generated code]
    
    272 272
         do  { expr' <- tcExpr expr res_ty
    
    273 273
             ; return (L loc expr') }
    
    274 274
     
    
    ... ... @@ -660,10 +660,10 @@ tcExpr expr@(RecordUpd { rupd_expr = record_expr
    660 660
            res_ty
    
    661 661
       = assert (notNull rbnds) $
    
    662 662
         do  { -- Expand the record update. See Note [Record Updates].
    
    663
    +
    
    663 664
             ; (ds_expr, ds_res_ty, err_msg)
    
    664 665
                 <- expandRecordUpd record_expr possible_parents rbnds res_ty
    
    665
    -        ; addErrCtxt err_msg $
    
    666
    -          setInGeneratedCode (OrigExpr expr) $
    
    666
    +        ; addExpansionErrCtxt (OrigExpr expr) err_msg $
    
    667 667
               do { -- Typecheck the expanded expression.
    
    668 668
                    expr' <- tcExpr ds_expr (Check ds_res_ty)
    
    669 669
                    -- NB: it's important to use ds_res_ty and not res_ty here.
    
    ... ... @@ -718,7 +718,7 @@ tcExpr (HsProjection _ _) _ = panic "GHC.Tc.Gen.Expr: tcExpr: HsProjection: Not
    718 718
     -- Here we get rid of it and add the finalizers to the global environment.
    
    719 719
     -- See Note [Delaying modFinalizers in untyped splices] in GHC.Rename.Splice.
    
    720 720
     tcExpr (HsTypedSplice ext splice)   res_ty = tcTypedSplice ext splice res_ty
    
    721
    -tcExpr e@(HsTypedBracket _ext body)    res_ty = tcTypedBracket e body res_ty
    
    721
    +tcExpr e@(HsTypedBracket _ext body) res_ty = tcTypedBracket e body res_ty
    
    722 722
     
    
    723 723
     tcExpr e@(HsUntypedBracket ps body) res_ty = tcUntypedBracket e body ps res_ty
    
    724 724
     tcExpr (HsUntypedSplice splice _)   res_ty
    
    ... ... @@ -753,18 +753,9 @@ tcExpr (SectionR {}) ty = pprPanic "tcExpr:SectionR" (ppr ty)
    753 753
     -}
    
    754 754
     
    
    755 755
     tcXExpr :: XXExprGhcRn -> ExpRhoType -> TcM (HsExpr GhcTc)
    
    756
    -
    
    757
    -tcXExpr (PopErrCtxt e) res_ty
    
    758
    -  = do popErrCtxt $ -- See Part 3 of Note [Expanding HsDo with XXExprGhcRn] in `GHC.Tc.Gen.Do`
    
    759
    -         addExprCtxt e $
    
    760
    -         tcExpr e res_ty
    
    761
    -
    
    762 756
     tcXExpr (ExpandedThingRn o e) res_ty
    
    763
    -   = setInGeneratedCode o $
    
    764
    -     -- e is the expanded expression of o, so we need to set the error ctxt to generated
    
    765
    -     -- see Note [Error Context Stack] in `GHC.Tc.Type.LclEnv`
    
    766
    -        mkExpandedTc o <$> -- necessary for hpc ticks
    
    767
    -          tcExpr e res_ty
    
    757
    +   = mkExpandedTc o <$> -- necessary for hpc ticks
    
    758
    +         tcExpr e res_ty
    
    768 759
     
    
    769 760
     -- For record selection, same as HsVar case
    
    770 761
     tcXExpr xe res_ty = tcApp (XExpr xe) res_ty
    
    ... ... @@ -1480,7 +1471,7 @@ expandRecordUpd record_expr possible_parents rbnds res_ty
    1480 1471
                  ds_expr = HsLet noExtField let_binds (wrapGenSpan case_expr)
    
    1481 1472
     
    
    1482 1473
                  case_expr :: HsExpr GhcRn
    
    1483
    -             case_expr = HsCase RecUpd record_expr
    
    1474
    +             case_expr = HsCase RecUpd (wrapGenSpan (unLoc record_expr))
    
    1484 1475
                            $ mkMatchGroup (Generated OtherExpansion DoPmc) (wrapGenSpan matches)
    
    1485 1476
                  matches :: [LMatch GhcRn (LHsExpr GhcRn)]
    
    1486 1477
                  matches = map make_pat (NE.toList relevant_cons)
    

  • compiler/GHC/Tc/Gen/Head.hs
    ... ... @@ -26,7 +26,7 @@ module GHC.Tc.Gen.Head
    26 26
            , nonBidirectionalErr
    
    27 27
     
    
    28 28
            , pprArgInst
    
    29
    -       , addExprCtxt, addFunResCtxt ) where
    
    29
    +       , addExprCtxt, addLExprCtxt, addFunResCtxt ) where
    
    30 30
     
    
    31 31
     import {-# SOURCE #-} GHC.Tc.Gen.Expr( tcExpr, tcCheckPolyExprNC, tcPolyLExprSig )
    
    32 32
     import {-# SOURCE #-} GHC.Tc.Gen.Splice( getUntypedSpliceBody )
    
    ... ... @@ -49,6 +49,7 @@ import GHC.Tc.Solver ( InferMode(..), simplifyInfer )
    49 49
     import GHC.Tc.Utils.Env
    
    50 50
     import GHC.Tc.Utils.TcMType
    
    51 51
     import GHC.Tc.Types.Origin
    
    52
    +import GHC.Tc.Types.ErrCtxt ( srcCodeOriginErrCtxMsg )
    
    52 53
     import GHC.Tc.Types.Constraint( WantedConstraints )
    
    53 54
     import GHC.Tc.Utils.TcType as TcType
    
    54 55
     import GHC.Tc.Types.Evidence
    
    ... ... @@ -174,7 +175,7 @@ data HsExprArg (p :: TcPass) where -- See Note [HsExprArg]
    174 175
                    , eaql_larg    :: LHsExpr GhcRn       -- Original application, for
    
    175 176
                                                          -- location and error msgs
    
    176 177
                    , eaql_rn_fun  :: HsExpr GhcRn  -- Head of the argument if it is an application
    
    177
    -               , eaql_tc_fun  :: (HsExpr GhcTc, SrcSpan) -- Typechecked head
    
    178
    +               , eaql_tc_fun  :: (HsExpr GhcTc, SrcSpan) -- Typechecked head and its location span
    
    178 179
                    , eaql_fun_ue  :: UsageEnv -- Usage environment of the typechecked head (QLA5)
    
    179 180
                    , eaql_args    :: [HsExprArg 'TcpInst]    -- Args: instantiated, not typechecked
    
    180 181
                    , eaql_wanted  :: WantedConstraints
    
    ... ... @@ -217,7 +218,7 @@ type family XPass (p :: TcPass) where
    217 218
     
    
    218 219
     mkEValArg :: SrcSpan -> LHsExpr GhcRn -> HsExprArg 'TcpRn
    
    219 220
     mkEValArg src_loc e = EValArg { ea_arg = e, ea_loc_span = src_loc
    
    220
    -                           , ea_arg_ty = noExtField }
    
    221
    +                              , ea_arg_ty = noExtField }
    
    221 222
     
    
    222 223
     mkETypeArg :: SrcSpan -> LHsWcType GhcRn -> HsExprArg 'TcpRn
    
    223 224
     mkETypeArg src_loc hs_ty =
    
    ... ... @@ -244,18 +245,18 @@ splitHsApps e = go e noSrcSpan []
    244 245
         go :: HsExpr GhcRn -> SrcSpan -> [HsExprArg 'TcpRn]
    
    245 246
            -> TcM ((HsExpr GhcRn, SrcSpan), [HsExprArg 'TcpRn])
    
    246 247
         -- Modify the SrcSpan as we walk inwards, so it describes the next argument
    
    247
    -    go (HsPar _ (L l fun))        sloc args = go fun (locA l) (EWrap (EPar sloc)     : args)
    
    248
    -    go (HsPragE _ p (L l fun))    sloc args = go fun (locA l) (EPrag      sloc p     : args)
    
    249
    -    go (HsAppType _ (L l fun) ty) sloc args = go fun (locA l) (mkETypeArg sloc ty    : args)
    
    250
    -    go (HsApp _ (L l fun) arg)    sloc args = go fun (locA l) (mkEValArg  sloc arg   : args)
    
    248
    +    go (HsPar _ (L l fun))        lspan args = go fun (locA l) (EWrap (EPar lspan)     : args)
    
    249
    +    go (HsPragE _ p (L l fun))    lspan args = go fun (locA l) (EPrag      lspan p     : args)
    
    250
    +    go (HsAppType _ (L l fun) ty) lspan args = go fun (locA l) (mkETypeArg lspan ty    : args)
    
    251
    +    go (HsApp _ (L l fun) arg)    lspan args = go fun (locA l) (mkEValArg  lspan arg   : args)
    
    251 252
     
    
    252 253
         -- See Note [Looking through Template Haskell splices in splitHsApps]
    
    253 254
         go e@(HsUntypedSplice splice_res splice) _ args
    
    254 255
           = do { fun <- getUntypedSpliceBody splice_res
    
    255
    -           ; go fun sloc' (EWrap (EExpand e) : args) }
    
    256
    +           ; go fun lspan' (EWrap (EExpand e) : args) }
    
    256 257
           where
    
    257
    -        sloc' :: SrcSpan
    
    258
    -        sloc' = case splice of
    
    258
    +        lspan' :: SrcSpan
    
    259
    +        lspan' = case splice of
    
    259 260
                 HsUntypedSpliceExpr _ (L l _) -> locA l -- l :: SrcAnn AnnListItem
    
    260 261
                 HsQuasiQuote _ _ (L l _)      -> locA l -- l :: SrcAnn NoEpAnns
    
    261 262
                 (XUntypedSplice (HsImplicitLiftSplice _ _ _ (L l _))) -> locA l
    
    ... ... @@ -269,11 +270,10 @@ splitHsApps e = go e noSrcSpan []
    269 270
                         -- and its hard to say exactly what that is
    
    270 271
                    : EWrap (EExpand e)
    
    271 272
                    : args )
    
    272
    -    go (XExpr (PopErrCtxt fun)) sloc args = go fun sloc args
    
    273 273
           -- look through PopErrCtxt (cf. T17594f) we do not want to lose the opportunity of calling tcEValArgQL
    
    274 274
           -- unlike HsPar, it is okay to forget about the PopErrCtxts as it does not persist over in GhcTc land
    
    275 275
     
    
    276
    -    go e sloc args = pure ((e, sloc), args)
    
    276
    +    go e lspan args = pure ((e, lspan), args)
    
    277 277
     
    
    278 278
     
    
    279 279
     -- | Rebuild an application: takes a type-checked application head
    
    ... ... @@ -456,8 +456,8 @@ tcInferAppHead :: (HsExpr GhcRn, SrcSpan)
    456 456
     --     cases are dealt with by splitHsApps.
    
    457 457
     --
    
    458 458
     -- See Note [tcApp: typechecking applications] in GHC.Tc.Gen.App
    
    459
    -tcInferAppHead (fun,fun_loc)
    
    460
    -  = setSrcSpan fun_loc $
    
    459
    +tcInferAppHead (fun,fun_lspan)
    
    460
    +  = setSrcSpan fun_lspan $
    
    461 461
         do { mb_tc_fun <- tcInferAppHead_maybe fun
    
    462 462
            ; case mb_tc_fun of
    
    463 463
                 Just (fun', fun_sigma) -> return (fun', fun_sigma)
    
    ... ... @@ -471,9 +471,9 @@ tcInferAppHead_maybe fun =
    471 471
         case fun of
    
    472 472
           HsVar _ nm                  -> Just <$> tcInferId nm
    
    473 473
           XExpr (HsRecSelRn f)        -> Just <$> tcInferRecSelId f
    
    474
    -      XExpr (ExpandedThingRn o e) -> Just <$> (setInGeneratedCode o $ -- We do not want to instantiate c.f. T19167
    
    475
    -                                                tcExprSigma False e)
    
    476
    -      XExpr (PopErrCtxt e)        -> tcInferAppHead_maybe e
    
    474
    +      XExpr (ExpandedThingRn o e) -> Just <$> (addExpansionErrCtxt o (srcCodeOriginErrCtxMsg o) $
    
    475
    +                                              -- We do not want to instantiate c.f. T19167
    
    476
    +                                                    tcExprSigma False e)
    
    477 477
           ExprWithTySig _ e hs_ty     -> Just <$> tcExprWithSig e hs_ty
    
    478 478
           HsOverLit _ lit             -> Just <$> tcInferOverLit lit
    
    479 479
           _                           -> return Nothing
    
    ... ... @@ -1109,5 +1109,17 @@ addExprCtxt e thing_inside
    1109 1109
        --    f x = _
    
    1110 1110
        -- when we don't want to say "In the expression: _",
    
    1111 1111
        -- because it is mentioned in the error message itself
    
    1112
    -      XExpr (PopErrCtxt _) -> thing_inside -- popErrCtxt shouldn't push ctxt. see typechecking let stmts
    
    1112
    +      HsPar{} -> thing_inside
    
    1113
    +      -- We don't want to say 'In the expression (e)',
    
    1114
    +      -- we just want to say 'In the expression, 'e'
    
    1115
    +      -- which will be handeled by the recursive call in thing_inside
    
    1116
    +      XExpr (ExpandedThingRn o _) -> addExpansionErrCtxt o (srcCodeOriginErrCtxMsg o) thing_inside
    
    1113 1117
           _ -> addErrCtxt (ExprCtxt e) thing_inside -- no op in generated code
    
    1118
    +
    
    1119
    +
    
    1120
    +addLExprCtxt :: LHsExpr GhcRn -> TcRn a -> TcRn a
    
    1121
    +addLExprCtxt (L lspan e) thing_inside
    
    1122
    +  | (RealSrcSpan{}) <- locA lspan
    
    1123
    +  = addExprCtxt e thing_inside
    
    1124
    +  | otherwise
    
    1125
    +  = thing_inside

  • compiler/GHC/Tc/Gen/Match.hs
    ... ... @@ -57,6 +57,7 @@ import GHC.Tc.Gen.Bind
    57 57
     import GHC.Tc.Utils.Concrete ( hasFixedRuntimeRep_syntactic )
    
    58 58
     import GHC.Tc.Utils.Unify
    
    59 59
     import GHC.Tc.Types.Origin
    
    60
    +import GHC.Tc.Types.ErrCtxt ( srcCodeOriginErrCtxMsg )
    
    60 61
     import GHC.Tc.Types.Evidence
    
    61 62
     import GHC.Rename.Env ( irrefutableConLikeTc )
    
    62 63
     
    
    ... ... @@ -330,6 +331,7 @@ tcMatch tc_body pat_tys rhs_ty match
    330 331
             add_match_ctxt thing_inside = case ctxt of
    
    331 332
                 LamAlt LamSingle -> thing_inside
    
    332 333
                 StmtCtxt (HsDoStmt{}) -> thing_inside -- this is an expanded do stmt
    
    334
    +            RecUpd -> thing_inside -- record update is Expanded out so ignore it
    
    333 335
                 _          -> addErrCtxt (MatchInCtxt match) thing_inside
    
    334 336
     
    
    335 337
     -------------
    
    ... ... @@ -404,9 +406,9 @@ tcDoStmts doExpr@(DoExpr _) ss@(L l stmts) res_ty
    404 406
                       ; return (HsDo res_ty doExpr (L l stmts')) }
    
    405 407
               else do { expanded_expr <- expandDoStmts doExpr stmts -- Do expansion on the fly
    
    406 408
                       ; let orig = HsDo noExtField doExpr ss
    
    407
    -                  ; setInGeneratedCode (OrigExpr orig) $ do
    
    408
    -                      { e' <- tcMonoLExpr expanded_expr res_ty
    
    409
    -                      ; return (mkExpandedExprTc orig (unLoc e'))}
    
    409
    +                  ; addExpansionErrCtxt (OrigExpr orig) (srcCodeOriginErrCtxMsg (OrigExpr orig)) $
    
    410
    +                    do { e' <- tcMonoLExpr expanded_expr res_ty
    
    411
    +                       ; return (mkExpandedExprTc orig (unLoc e'))}
    
    410 412
                       }
    
    411 413
             }
    
    412 414
     
    

  • compiler/GHC/Tc/Instance/Class.hs
    ... ... @@ -61,7 +61,6 @@ import GHC.Unit.Module.Warnings
    61 61
     
    
    62 62
     import GHC.Hs
    
    63 63
     
    
    64
    -import Language.Haskell.Syntax.Basic (FieldLabelString(..))
    
    65 64
     import GHC.Tc.Errors.Types
    
    66 65
     
    
    67 66
     import Data.Maybe
    

  • compiler/GHC/Tc/Types/ErrCtxt.hs
    ... ... @@ -4,7 +4,7 @@
    4 4
     {-# LANGUAGE UndecidableInstances #-}
    
    5 5
     
    
    6 6
     module GHC.Tc.Types.ErrCtxt
    
    7
    -  ( ErrCtxt, ErrCtxtMsg(..)
    
    7
    +  ( ErrCtxt (..), ErrCtxtMsg(..), ErrCtxtMsgM,  CodeSrcFlag (..), srcCodeOriginErrCtxMsg
    
    8 8
       , UserSigType(..), FunAppCtxtFunArg(..)
    
    9 9
       , TyConInstFlavour(..)
    
    10 10
       )
    
    ... ... @@ -23,7 +23,7 @@ import GHC.Tc.Zonk.Monad ( ZonkM )
    23 23
     
    
    24 24
     import GHC.Types.Basic       ( TyConFlavour )
    
    25 25
     import GHC.Types.Name        ( Name )
    
    26
    -import GHC.Types.SrcLoc      ( SrcSpan )
    
    26
    +import GHC.Types.SrcLoc      ( SrcSpan, unLoc )
    
    27 27
     import GHC.Types.Var         ( Id, TyCoVar )
    
    28 28
     import GHC.Types.Var.Env     ( TidyEnv )
    
    29 29
     
    
    ... ... @@ -48,15 +48,22 @@ import qualified Data.List.NonEmpty as NE
    48 48
     
    
    49 49
     --------------------------------------------------------------------------------
    
    50 50
     
    
    51
    +type ErrCtxtMsgM = TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)
    
    52
    +
    
    51 53
     -- | Additional context to include in an error message, e.g.
    
    52 54
     -- "In the type signature ...", "In the ambiguity check for ...", etc.
    
    53
    -type ErrCtxt = (Bool, TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg))
    
    54
    -        -- Monadic so that we have a chance
    
    55
    -        -- to deal with bound type variables just before error
    
    56
    -        -- message construction
    
    55
    +data ErrCtxt = MkErrCtxt CodeSrcFlag ErrCtxtMsgM
    
    56
    +             -- Monadic so that we have a chance
    
    57
    +             -- to deal with bound type variables just before error
    
    58
    +             -- message construction
    
    59
    +
    
    60
    +             -- Bool:  True <=> this is a landmark context; do not
    
    61
    +             --                 discard it when trimming for display
    
    57 62
     
    
    58
    -        -- Bool:  True <=> this is a landmark context; do not
    
    59
    -        --                 discard it when trimming for display
    
    63
    +data CodeSrcFlag = VanillaUserSrcCode
    
    64
    +                 | LandmarkUserSrcCode
    
    65
    +                 | ExpansionCodeCtxt SrcCodeOrigin
    
    66
    +                   -- INVARIANT: SHOULD NEVER APPEAR IN A ExpansionCodeCtxt in CodeSrcFlag ErrCtxt on stack
    
    60 67
     
    
    61 68
     --------------------------------------------------------------------------------
    
    62 69
     -- Error message contexts
    
    ... ... @@ -221,3 +228,10 @@ data ErrCtxtMsg
    221 228
       | MergeSignaturesCtxt !UnitState !ModuleName ![InstantiatedModule]
    
    222 229
       -- | While checking that a module implements a Backpack signature.
    
    223 230
       | CheckImplementsCtxt !UnitState !Module !InstantiatedModule
    
    231
    +
    
    232
    +
    
    233
    +srcCodeOriginErrCtxMsg :: SrcCodeOrigin -> ErrCtxtMsg
    
    234
    +srcCodeOriginErrCtxMsg (OrigExpr e) = ExprCtxt e
    
    235
    +srcCodeOriginErrCtxMsg (OrigStmt s f) = StmtErrCtxt (HsDoStmt f) (unLoc s)
    
    236
    +srcCodeOriginErrCtxMsg (OrigPat  p) = PatCtxt p
    
    237
    +srcCodeOriginErrCtxMsg (PopErrCtxt) = error "Shouldn't happen srcCodeOriginErr"

  • compiler/GHC/Tc/Types/LclEnv.hs
    ... ... @@ -28,7 +28,7 @@ module GHC.Tc.Types.LclEnv (
    28 28
     
    
    29 29
       , addLclEnvErrCtxt
    
    30 30
     
    
    31
    -  , ErrCtxtStack (..)
    
    31
    +  , ErrCtxtStack
    
    32 32
       , ArrowCtxt(..)
    
    33 33
       , ThBindEnv
    
    34 34
       , TcTypeEnv
    
    ... ... @@ -36,7 +36,7 @@ module GHC.Tc.Types.LclEnv (
    36 36
     
    
    37 37
     import GHC.Prelude
    
    38 38
     
    
    39
    -import GHC.Hs ( SrcCodeOrigin )
    
    39
    +import GHC.Hs ( SrcCodeOrigin (..) )
    
    40 40
     import GHC.Tc.Utils.TcType ( TcLevel )
    
    41 41
     import GHC.Tc.Errors.Types ( TcRnMessage )
    
    42 42
     
    
    ... ... @@ -92,15 +92,19 @@ data TcLclEnv -- Changes as we move inside an expression
    92 92
         }
    
    93 93
     
    
    94 94
     {-
    
    95
    -Note [Error Context Stack]
    
    96
    -~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    95
    +
    
    96
    +Note [ErrCtxtStack Manipulation]
    
    97
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    98
    +The ErrCtxtStack is a list of ErrCtxt
    
    99
    +ANI: TODO. explain how this works. When is the top of the stack overwritten? When an error ctxt pushed on top
    
    100
    +
    
    97 101
     This data structure keeps track of two things:
    
    98 102
     1. Are we type checking a compiler generated/non-user written code.
    
    99 103
     2. The trail of the error messages that have been added in route to the current expression
    
    100 104
     
    
    101 105
     * When the `ErrCtxtStack` is a `UserCodeCtxt`,
    
    102 106
       - the current expression being typechecked is user written
    
    103
    -* When the `ErrorCtxtStack` is a `GeneratedCodeCtxt`
    
    107
    +* When the `ErrorCtxtStack` is a `ExpansionCodeCtxt`
    
    104 108
       - the current expression being typechecked is compiler generated;
    
    105 109
       - the original, possibly user written, source code thing is stored in `src_code_origin` field.
    
    106 110
       - the `src_code_origin` is what will be blamed in the error message
    
    ... ... @@ -109,39 +113,22 @@ This data structure keeps track of two things:
    109 113
     
    
    110 114
     
    
    111 115
     -- See Note [Error Context Stack]
    
    112
    -data ErrCtxtStack
    
    113
    -  = UserCodeCtxt { lcl_err_ctxt :: [ErrCtxt] } -- ^ Trail of error messages
    
    114
    -  | GeneratedCodeCtxt { src_code_origin :: SrcCodeOrigin -- ^ Original, user written code
    
    115
    -                      , lcl_err_ctxt ::  [ErrCtxt] } -- ^ Trail of error messages
    
    116
    -
    
    117
    --- | Are we in a generated context?
    
    118
    -isGeneratedCodeCtxt :: ErrCtxtStack -> Bool
    
    119
    -isGeneratedCodeCtxt UserCodeCtxt{} = False
    
    120
    -isGeneratedCodeCtxt _ = True
    
    116
    +type ErrCtxtStack = [ErrCtxt]
    
    121 117
     
    
    122 118
     -- | Get the original source code
    
    123 119
     get_src_code_origin :: ErrCtxtStack -> Maybe SrcCodeOrigin
    
    124
    -get_src_code_origin (UserCodeCtxt{}) = Nothing
    
    125
    -                                -- we are in user code, so blame the expression in hand
    
    126
    -get_src_code_origin es = Just $ src_code_origin es
    
    127
    -                   -- we are in generated code, so extract the original expression
    
    128
    -
    
    129
    --- | Modify the error context stack
    
    130
    ---   N.B. If we are in a generated context, any updates to the context stack are ignored.
    
    131
    ---   We want to blame the errors that appear in a generated expression
    
    132
    ---   to the original, user written code
    
    133
    -modify_err_ctxt_stack :: ([ErrCtxt] -> [ErrCtxt]) -> ErrCtxtStack -> ErrCtxtStack
    
    134
    -modify_err_ctxt_stack f (UserCodeCtxt e) =  UserCodeCtxt (f e)
    
    135
    -modify_err_ctxt_stack _ c = c -- any updates on the err context in a generated context should be ignored
    
    136
    -
    
    120
    +get_src_code_origin (MkErrCtxt (ExpansionCodeCtxt origSrcCode) _ : _) = Just origSrcCode
    
    121
    +                   -- we are in generated code, due to the expansion of the original syntax origSrcCode
    
    122
    +get_src_code_origin _ = Nothing
    
    123
    +                   -- we are in user code, so blame the expression in hand
    
    137 124
     
    
    138 125
     data TcLclCtxt
    
    139 126
       = TcLclCtxt {
    
    140
    -        tcl_loc        :: RealSrcSpan,     -- Source span
    
    141
    -        tcl_ctxt       :: ErrCtxtStack,    -- See Note [Error Context Stack]
    
    142
    -        tcl_tclvl      :: TcLevel,
    
    143
    -        tcl_bndrs      :: TcBinderStack,   -- Used for reporting relevant bindings,
    
    144
    -                                           -- and for tidying type
    
    127
    +        tcl_loc         :: RealSrcSpan,     -- Source span
    
    128
    +        tcl_err_ctxt    :: ErrCtxtStack,    -- See Note [Error Context Stack]
    
    129
    +        tcl_tclvl       :: TcLevel,
    
    130
    +        tcl_bndrs       :: TcBinderStack,   -- Used for reporting relevant bindings,
    
    131
    +                                            -- and for tidying type
    
    145 132
     
    
    146 133
             tcl_rdr :: LocalRdrEnv,         -- Local name envt
    
    147 134
                     -- Maintained during renaming, of course, but also during
    
    ... ... @@ -203,28 +190,40 @@ getLclEnvLoc :: TcLclEnv -> RealSrcSpan
    203 190
     getLclEnvLoc = tcl_loc . tcl_lcl_ctxt
    
    204 191
     
    
    205 192
     getLclEnvErrCtxt :: TcLclEnv -> [ErrCtxt]
    
    206
    -getLclEnvErrCtxt = lcl_err_ctxt . tcl_ctxt . tcl_lcl_ctxt
    
    193
    +getLclEnvErrCtxt = tcl_err_ctxt . tcl_lcl_ctxt
    
    207 194
     
    
    208
    -setLclEnvErrCtxt :: [ErrCtxt] -> TcLclEnv -> TcLclEnv
    
    209
    -setLclEnvErrCtxt ctxt = modifyLclCtxt (\env -> env { tcl_ctxt = modify_err_ctxt_stack (\ _ -> ctxt) (tcl_ctxt env) })
    
    195
    +setLclEnvErrCtxt :: ErrCtxtStack -> TcLclEnv -> TcLclEnv
    
    196
    +setLclEnvErrCtxt ctxt = modifyLclCtxt (\env -> env { tcl_err_ctxt = ctxt })
    
    210 197
     
    
    211 198
     addLclEnvErrCtxt :: ErrCtxt -> TcLclEnv -> TcLclEnv
    
    212
    -addLclEnvErrCtxt ec = modifyLclCtxt (\env -> env { tcl_ctxt = modify_err_ctxt_stack (\ctxt -> ec : ctxt) (tcl_ctxt env) })
    
    199
    +addLclEnvErrCtxt ec = setLclEnvSrcCodeOrigin ec
    
    213 200
     
    
    214 201
     getLclEnvSrcCodeOrigin :: TcLclEnv -> Maybe SrcCodeOrigin
    
    215
    -getLclEnvSrcCodeOrigin = get_src_code_origin . tcl_ctxt . tcl_lcl_ctxt
    
    216
    -
    
    217
    -setLclEnvSrcCodeOrigin :: SrcCodeOrigin -> TcLclEnv -> TcLclEnv
    
    218
    -setLclEnvSrcCodeOrigin o = modifyLclCtxt (setLclCtxtSrcCodeOrigin o)
    
    219
    -
    
    220
    -setLclCtxtSrcCodeOrigin :: SrcCodeOrigin -> TcLclCtxt -> TcLclCtxt
    
    221
    -setLclCtxtSrcCodeOrigin o ctxt = ctxt { tcl_ctxt = GeneratedCodeCtxt o (lcl_err_ctxt $ tcl_ctxt ctxt) }
    
    202
    +getLclEnvSrcCodeOrigin = get_src_code_origin . tcl_err_ctxt . tcl_lcl_ctxt
    
    203
    +
    
    204
    +setLclEnvSrcCodeOrigin :: ErrCtxt -> TcLclEnv -> TcLclEnv
    
    205
    +setLclEnvSrcCodeOrigin ec = modifyLclCtxt (setLclCtxtSrcCodeOrigin ec)
    
    206
    +
    
    207
    +-- See Note [ErrCtxt Stack Manipulation]
    
    208
    +setLclCtxtSrcCodeOrigin :: ErrCtxt -> TcLclCtxt -> TcLclCtxt
    
    209
    +setLclCtxtSrcCodeOrigin ec lclCtxt
    
    210
    +  | MkErrCtxt (ExpansionCodeCtxt PopErrCtxt) _ <- ec
    
    211
    +  = lclCtxt { tcl_err_ctxt = tail (tcl_err_ctxt lclCtxt) }
    
    212
    +  | MkErrCtxt (ExpansionCodeCtxt _) _ : ecs <- tcl_err_ctxt lclCtxt
    
    213
    +  , MkErrCtxt (ExpansionCodeCtxt _) _ <- ec
    
    214
    +  = lclCtxt { tcl_err_ctxt =  ec : ecs }
    
    215
    +  | otherwise
    
    216
    +  = lclCtxt { tcl_err_ctxt = ec : tcl_err_ctxt lclCtxt }
    
    222 217
     
    
    223 218
     lclCtxtInGeneratedCode :: TcLclCtxt -> Bool
    
    224
    -lclCtxtInGeneratedCode = isGeneratedCodeCtxt . tcl_ctxt
    
    219
    +lclCtxtInGeneratedCode lclCtxt
    
    220
    +  | (MkErrCtxt (ExpansionCodeCtxt _) _ : _) <- tcl_err_ctxt lclCtxt
    
    221
    +  = True
    
    222
    +  | otherwise
    
    223
    +  = False
    
    225 224
     
    
    226 225
     lclEnvInGeneratedCode :: TcLclEnv -> Bool
    
    227
    -lclEnvInGeneratedCode = lclCtxtInGeneratedCode . tcl_lcl_ctxt
    
    226
    +lclEnvInGeneratedCode =  lclCtxtInGeneratedCode . tcl_lcl_ctxt
    
    228 227
     
    
    229 228
     getLclEnvBinderStack :: TcLclEnv -> TcBinderStack
    
    230 229
     getLclEnvBinderStack = tcl_bndrs . tcl_lcl_ctxt
    

  • compiler/GHC/Tc/Types/Origin.hs
    ... ... @@ -837,8 +837,7 @@ exprCtOrigin e@(HsProjection _ _) = ExpansionOrigin (OrigExpr e)
    837 837
     exprCtOrigin e@(RecordUpd{})      = ExpansionOrigin (OrigExpr e)
    
    838 838
     exprCtOrigin e@(HsGetField{})     = ExpansionOrigin (OrigExpr e)
    
    839 839
     exprCtOrigin (XExpr (ExpandedThingRn o _)) = ExpansionOrigin o
    
    840
    -exprCtOrigin (XExpr (PopErrCtxt e)) = exprCtOrigin e
    
    841
    -exprCtOrigin (XExpr (HsRecSelRn f))  = OccurrenceOfRecSel (foExt f)
    
    840
    +exprCtOrigin (XExpr (HsRecSelRn f))  = OccurrenceOfRecSel $ L (getLoc $ foLabel f) (foExt f)
    
    842 841
     
    
    843 842
     srcCodeOriginCtOrigin :: HsExpr GhcRn -> Maybe SrcCodeOrigin -> CtOrigin
    
    844 843
     srcCodeOriginCtOrigin e Nothing = exprCtOrigin e
    
    ... ... @@ -889,6 +888,7 @@ pprCtOrigin (ExpansionOrigin o)
    889 888
             OrigExpr (ExplicitList{}) -> text "an overloaded list"
    
    890 889
             OrigExpr (HsIf{}) -> text "an if-then-else expression"
    
    891 890
             OrigExpr e -> text "the expression" <+> (ppr e)
    
    891
    +        PopErrCtxt -> text "Shouldn't Happen PopErrCtxt"
    
    892 892
     
    
    893 893
     pprCtOrigin (GivenSCOrigin sk d blk)
    
    894 894
       = vcat [ ctoHerald <+> pprSkolInfo sk
    
    ... ... @@ -1121,6 +1121,7 @@ ppr_br (ExpansionOrigin (OrigExpr (HsIf{}))) = text "an if-then-else expression"
    1121 1121
     ppr_br (ExpansionOrigin (OrigExpr e)) = text "an expression" <+> ppr e
    
    1122 1122
     ppr_br (ExpansionOrigin (OrigStmt{})) = text "a do statement"
    
    1123 1123
     ppr_br (ExpansionOrigin (OrigPat{})) = text "a do statement"
    
    1124
    +ppr_br (ExpansionOrigin PopErrCtxt) = text "SHOULDN'T HAPPEN POPERRORCTXT"
    
    1124 1125
     ppr_br (ExpectedTySyntax o _) = ppr_br o
    
    1125 1126
     ppr_br (ExpectedFunTySyntaxOp{}) = text "a rebindable syntax operator"
    
    1126 1127
     ppr_br (ExpectedFunTyViewPat{}) = text "a view pattern"
    

  • compiler/GHC/Tc/Utils/Monad.hs
    ... ... @@ -63,7 +63,7 @@ module GHC.Tc.Utils.Monad(
    63 63
       -- * Error management
    
    64 64
       getSrcCodeOrigin,
    
    65 65
       getSrcSpanM, setSrcSpan, setSrcSpanA, addLocM,
    
    66
    -  inGeneratedCode, setInGeneratedCode,
    
    66
    +  inGeneratedCode, -- setInGeneratedCode,
    
    67 67
       wrapLocM, wrapLocFstM, wrapLocFstMA, wrapLocSndM, wrapLocSndMA, wrapLocM_,
    
    68 68
       wrapLocMA_,wrapLocMA,
    
    69 69
       getErrsVar, setErrsVar,
    
    ... ... @@ -88,6 +88,7 @@ module GHC.Tc.Utils.Monad(
    88 88
     
    
    89 89
       -- * Context management for the type checker
    
    90 90
       getErrCtxt, setErrCtxt, addErrCtxt, addErrCtxtM, addLandmarkErrCtxt,
    
    91
    +  addExpansionErrCtxt, addExpansionErrCtxtM,
    
    91 92
       addLandmarkErrCtxtM, popErrCtxt, getCtLocM, setCtLocM, mkCtLocEnv,
    
    92 93
     
    
    93 94
       -- * Diagnostic message generation (type checker)
    
    ... ... @@ -172,6 +173,7 @@ import GHC.Tc.Types -- Re-export all
    172 173
     import GHC.Tc.Types.Constraint
    
    173 174
     import GHC.Tc.Types.CtLoc
    
    174 175
     import GHC.Tc.Types.Evidence
    
    176
    +import GHC.Tc.Types.ErrCtxt
    
    175 177
     import GHC.Tc.Types.LclEnv
    
    176 178
     import GHC.Tc.Types.Origin
    
    177 179
     import GHC.Tc.Types.TcRef
    
    ... ... @@ -418,7 +420,7 @@ initTcWithGbl hsc_env gbl_env loc do_this
    418 420
                     tcl_lcl_ctxt   = TcLclCtxt {
    
    419 421
                     tcl_loc        = loc,
    
    420 422
                     -- tcl_loc should be over-ridden very soon!
    
    421
    -                tcl_ctxt       = UserCodeCtxt [],
    
    423
    +                tcl_err_ctxt   = [],
    
    422 424
                     tcl_rdr        = emptyLocalRdrEnv,
    
    423 425
                     tcl_th_ctxt    = topLevel,
    
    424 426
                     tcl_th_bndrs   = emptyNameEnv,
    
    ... ... @@ -1077,23 +1079,27 @@ inGeneratedCode = lclEnvInGeneratedCode <$> getLclEnv
    1077 1079
     setSrcSpan :: SrcSpan -> TcRn a -> TcRn a
    
    1078 1080
     -- See Note [Error contexts in generated code]
    
    1079 1081
     setSrcSpan (RealSrcSpan loc _) thing_inside
    
    1080
    -  = updLclCtxt (\env -> env { tcl_loc = loc
    
    1081
    -                            , tcl_ctxt = UserCodeCtxt (lcl_err_ctxt $ tcl_ctxt env)})
    
    1082
    -              thing_inside
    
    1082
    +  = updLclCtxt (\env -> env { tcl_loc = loc }) thing_inside
    
    1083 1083
     
    
    1084 1084
     setSrcSpan (UnhelpfulSpan _) thing_inside
    
    1085 1085
       = thing_inside
    
    1086 1086
     
    
    1087 1087
     getSrcCodeOrigin :: TcRn (Maybe SrcCodeOrigin)
    
    1088
    -getSrcCodeOrigin = getLclEnvSrcCodeOrigin <$> getLclEnv
    
    1088
    +getSrcCodeOrigin =
    
    1089
    +  do inGenCode <- inGeneratedCode
    
    1090
    +     if inGenCode
    
    1091
    +       then getLclEnvSrcCodeOrigin <$> getLclEnv
    
    1092
    +       else return Nothing
    
    1093
    +
    
    1089 1094
     
    
    1090 1095
     -- | Mark the inner computation as being done inside generated code.
    
    1091 1096
     --
    
    1092 1097
     -- See Note [Error contexts in generated code]
    
    1093 1098
     -- See Note [Error Context Stack]
    
    1094
    -setInGeneratedCode :: SrcCodeOrigin -> TcRn a -> TcRn a
    
    1095
    -setInGeneratedCode sco thing_inside =
    
    1096
    -  updLclCtxt (setLclCtxtSrcCodeOrigin sco) thing_inside
    
    1099
    +-- setInGeneratedCode :: SrcCodeOrigin -> TcRn a -> TcRn a
    
    1100
    +-- setInGeneratedCode sco thing_inside =
    
    1101
    +--   -- updLclCtxt setLclCtxtInGenCode $
    
    1102
    +--   updLclCtxt (setLclCtxtSrcCodeOrigin sco) thing_inside
    
    1097 1103
     
    
    1098 1104
     setSrcSpanA :: EpAnn ann -> TcRn a -> TcRn a
    
    1099 1105
     setSrcSpanA l = setSrcSpan (locA l)
    
    ... ... @@ -1341,12 +1347,20 @@ addErrCtxt :: ErrCtxtMsg -> TcM a -> TcM a
    1341 1347
     {-# INLINE addErrCtxt #-}   -- Note [Inlining addErrCtxt]
    
    1342 1348
     addErrCtxt msg = addErrCtxtM (\env -> return (env, msg))
    
    1343 1349
     
    
    1350
    +addExpansionErrCtxt :: SrcCodeOrigin -> ErrCtxtMsg -> TcM a -> TcM a
    
    1351
    +{-# INLINE addExpansionErrCtxt #-}   -- Note [Inlining addErrCtxt]
    
    1352
    +addExpansionErrCtxt o msg = addExpansionErrCtxtM o (\env -> return (env, msg))
    
    1353
    +
    
    1344 1354
     -- | Add a message to the error context. This message may do tidying.
    
    1345 1355
     --   NB. No op in generated code
    
    1346 1356
     --   See Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr
    
    1347 1357
     addErrCtxtM :: (TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)) -> TcM a -> TcM a
    
    1348 1358
     {-# INLINE addErrCtxtM #-}  -- Note [Inlining addErrCtxt]
    
    1349
    -addErrCtxtM ctxt = pushCtxt (False, ctxt)
    
    1359
    +addErrCtxtM ctxt = pushCtxt (MkErrCtxt VanillaUserSrcCode ctxt)
    
    1360
    +
    
    1361
    +addExpansionErrCtxtM :: SrcCodeOrigin -> (TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)) -> TcM a -> TcM a
    
    1362
    +{-# INLINE addExpansionErrCtxtM #-}  -- Note [Inlining addErrCtxt]
    
    1363
    +addExpansionErrCtxtM o ctxt = pushCtxt (MkErrCtxt (ExpansionCodeCtxt o) ctxt)
    
    1350 1364
     
    
    1351 1365
     -- | Add a fixed landmark message to the error context. A landmark
    
    1352 1366
     -- message is always sure to be reported, even if there is a lot of
    
    ... ... @@ -1360,7 +1374,7 @@ addLandmarkErrCtxt msg = addLandmarkErrCtxtM (\env -> return (env, msg))
    1360 1374
     -- and tidying.
    
    1361 1375
     addLandmarkErrCtxtM :: (TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)) -> TcM a -> TcM a
    
    1362 1376
     {-# INLINE addLandmarkErrCtxtM #-}  -- Note [Inlining addErrCtxt]
    
    1363
    -addLandmarkErrCtxtM ctxt = pushCtxt (True, ctxt)
    
    1377
    +addLandmarkErrCtxtM ctxt = pushCtxt (MkErrCtxt LandmarkUserSrcCode ctxt)
    
    1364 1378
     
    
    1365 1379
     -- | NB. no op in generated code
    
    1366 1380
     -- See Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr
    
    ... ... @@ -1371,9 +1385,7 @@ pushCtxt ctxt = updLclEnv (updCtxt ctxt)
    1371 1385
     updCtxt :: ErrCtxt -> TcLclEnv -> TcLclEnv
    
    1372 1386
     -- Do not update the context if we are in generated code
    
    1373 1387
     -- See Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr
    
    1374
    -updCtxt ctxt env
    
    1375
    -  | lclEnvInGeneratedCode env = env
    
    1376
    -  | otherwise = addLclEnvErrCtxt ctxt env
    
    1388
    +updCtxt ctxt env = addLclEnvErrCtxt ctxt env
    
    1377 1389
     
    
    1378 1390
     popErrCtxt :: TcM a -> TcM a
    
    1379 1391
     popErrCtxt thing_inside = updLclEnv (\env -> setLclEnvErrCtxt (pop $ getLclEnvErrCtxt env) env) $
    
    ... ... @@ -1834,11 +1846,17 @@ mkErrCtxt env ctxts
    1834 1846
      where
    
    1835 1847
        go :: Bool -> Int -> TidyEnv -> [ErrCtxt] -> TcM [ErrCtxtMsg]
    
    1836 1848
        go _ _ _   [] = return []
    
    1837
    -   go dbg n env ((is_landmark, ctxt) : ctxts)
    
    1838
    -     | is_landmark || n < mAX_CONTEXTS -- Too verbose || dbg
    
    1849
    +   go dbg n env (MkErrCtxt LandmarkUserSrcCode ctxt : ctxts)
    
    1850
    +     | n < mAX_CONTEXTS -- Too verbose || dbg
    
    1851
    +     = do { (env', msg) <- liftZonkM $ ctxt env
    
    1852
    +          ; rest <- go dbg n env' ctxts
    
    1853
    +          ; return (msg : rest) }
    
    1854
    +     | otherwise
    
    1855
    +     = go dbg n env ctxts
    
    1856
    +   go dbg n env (MkErrCtxt _ ctxt : ctxts)
    
    1857
    +     | n < mAX_CONTEXTS -- Too verbose || dbg
    
    1839 1858
          = do { (env', msg) <- liftZonkM $ ctxt env
    
    1840
    -          ; let n' = if is_landmark then n else n+1
    
    1841
    -          ; rest <- go dbg n' env' ctxts
    
    1859
    +          ; rest <- go dbg (n+1) env' ctxts
    
    1842 1860
               ; return (msg : rest) }
    
    1843 1861
          | otherwise
    
    1844 1862
          = go dbg n env ctxts
    

  • testsuite/tests/rebindable/rebindable6.stderr
    1
    -
    
    2 1
     rebindable6.hs:110:17: error: [GHC-39999]
    
    3 2
         • Ambiguous type variable ‘t0’ arising from a do statement
    
    4 3
           prevents the constraint ‘(HasSeq
    
    5 4
                                       (IO a -> t0 -> IO b))’ from being solved.
    
    6
    -        (maybe you haven't applied a function to enough arguments?)
    
    5
    +      (maybe you haven't applied a function to enough arguments?)
    
    7 6
           Relevant bindings include
    
    8 7
             g :: IO (Maybe b) (bound at rebindable6.hs:108:19)
    
    9 8
             f :: IO a (bound at rebindable6.hs:108:17)
    
    ... ... @@ -28,7 +27,7 @@ rebindable6.hs:111:17: error: [GHC-39999]
    28 27
         • Ambiguous type variables ‘t1’, ‘t0’ arising from a do statement
    
    29 28
           prevents the constraint ‘(HasBind
    
    30 29
                                       (IO (Maybe b) -> (Maybe b -> t1) -> t0))’ from being solved.
    
    31
    -        (maybe you haven't applied a function to enough arguments?)
    
    30
    +      (maybe you haven't applied a function to enough arguments?)
    
    32 31
           Relevant bindings include
    
    33 32
             g :: IO (Maybe b) (bound at rebindable6.hs:108:19)
    
    34 33
             test_do :: IO a -> IO (Maybe b) -> IO b
    
    ... ... @@ -50,9 +49,9 @@ rebindable6.hs:111:17: error: [GHC-39999]
    50 49
                      return b
    
    51 50
     
    
    52 51
     rebindable6.hs:112:17: error: [GHC-39999]
    
    53
    -    • Ambiguous type variable ‘t1’ arising from a use of ‘return’
    
    52
    +    • Ambiguous type variable ‘t1’ arising from a do statement
    
    54 53
           prevents the constraint ‘(HasReturn (b -> t1))’ from being solved.
    
    55
    -        (maybe you haven't applied a function to enough arguments?)
    
    54
    +      (maybe you haven't applied a function to enough arguments?)
    
    56 55
           Relevant bindings include
    
    57 56
             b :: b (bound at rebindable6.hs:111:23)
    
    58 57
             g :: IO (Maybe b) (bound at rebindable6.hs:108:19)
    
    ... ... @@ -71,3 +70,4 @@ rebindable6.hs:112:17: error: [GHC-39999]
    71 70
                 = do f
    
    72 71
                      Just (b :: b) <- g
    
    73 72
                      return b
    
    73
    +

  • testsuite/tests/typecheck/should_fail/DoExpansion1.stderr
    ... ... @@ -22,7 +22,7 @@ DoExpansion1.hs:15:54: warning: [GHC-39999] [-Wdeferred-type-errors (in -Wdefaul
    22 22
     DoExpansion1.hs:19:21: warning: [GHC-39999] [-Wdeferred-type-errors (in -Wdefault)]
    
    23 23
         • No instance for ‘Num String’ arising from the literal ‘1’
    
    24 24
         • In the first argument of ‘putStrLn’, namely ‘1’
    
    25
    -      In the expression: putStrLn 1
    
    25
    +      In a stmt of a 'do' block: putStrLn 1
    
    26 26
           In the expression:
    
    27 27
             do putStrLn 1
    
    28 28
                putStrLn "r2"
    
    ... ... @@ -31,7 +31,7 @@ DoExpansion1.hs:19:21: warning: [GHC-39999] [-Wdeferred-type-errors (in -Wdefaul
    31 31
     DoExpansion1.hs:25:21: warning: [GHC-39999] [-Wdeferred-type-errors (in -Wdefault)]
    
    32 32
         • No instance for ‘Num String’ arising from the literal ‘2’
    
    33 33
         • In the first argument of ‘putStrLn’, namely ‘2’
    
    34
    -      In the expression: putStrLn 2
    
    34
    +      In a stmt of a 'do' block: putStrLn 2
    
    35 35
           In the expression:
    
    36 36
             do putStrLn "r1"
    
    37 37
                putStrLn 2
    

  • testsuite/tests/typecheck/should_fail/DoExpansion2.stderr
    ... ... @@ -57,9 +57,7 @@ DoExpansion2.hs:34:22: warning: [GHC-83865] [-Wdeferred-type-errors (in -Wdefaul
    57 57
         • The function ‘getVal’ is applied to two visible arguments,
    
    58 58
             but its type ‘Int -> IO String’ has only one
    
    59 59
           In the expression: getVal 3 4
    
    60
    -      In the expression:
    
    61
    -        do Just x <- getVal 3 4
    
    62
    -           return x
    
    60
    +      In a stmt of a 'do' block: Just x <- getVal 3 4
    
    63 61
     
    
    64 62
     DoExpansion2.hs:39:19: warning: [GHC-83865] [-Wdeferred-type-errors (in -Wdefault)]
    
    65 63
         • Couldn't match type ‘[Char]’ with ‘Int’