Apoorv Ingle pushed to branch wip/ani/ctorig-stuff at Glasgow Haskell Compiler / GHC
Commits:
-
e12c1e9d
by Apoorv Ingle at 2025-06-29T20:27:28-05:00
-
d37adc69
by Apoorv Ingle at 2025-06-29T21:37:38-05:00
-
bde2465e
by Apoorv Ingle at 2025-07-02T16:02:03-05:00
-
e199446b
by Apoorv Ingle at 2025-07-02T16:11:44-05:00
-
2fb3b1ba
by Apoorv Ingle at 2025-07-07T00:16:14-05:00
-
e1864b1a
by Apoorv Ingle at 2025-07-13T21:14:25-05:00
17 changed files:
- compiler/GHC/Hs.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/Types/ErrCtxt.hs
- compiler/GHC/Tc/Types/LclEnv.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Tc/Utils/Unify.hs
- testsuite/tests/deSugar/should_compile/T10662.stderr
- testsuite/tests/deSugar/should_compile/T3263-1.stderr
- testsuite/tests/deSugar/should_compile/T3263-2.stderr
- testsuite/tests/ghci.debugger/scripts/break029.script
- testsuite/tests/rep-poly/RepPolyRecordUpdate.stderr
Changes:
... | ... | @@ -38,8 +38,6 @@ module GHC.Hs ( |
38 | 38 | HsModule(..), AnnsModule(..),
|
39 | 39 | HsParsedModule(..), XModulePs(..),
|
40 | 40 | |
41 | - SrcCodeCtxt(..), isUserCodeCtxt, isGeneratedCodeCtxt
|
|
42 | - |
|
43 | 41 | ) where
|
44 | 42 | |
45 | 43 | -- friends:
|
... | ... | @@ -149,17 +147,3 @@ data HsParsedModule = HsParsedModule { |
149 | 147 | -- the .hi file, so that we can force recompilation if any of
|
150 | 148 | -- them change (#3589)
|
151 | 149 | } |
152 | - |
|
153 | --- Used in TcLclCtxt.tcl_in_gen_code to mark if the current expression
|
|
154 | --- is a user generated code or a compiler generated expansion of some user written code
|
|
155 | -data SrcCodeCtxt
|
|
156 | - = UserCode
|
|
157 | - | GeneratedCode SrcCodeOrigin
|
|
158 | - |
|
159 | -isUserCodeCtxt :: SrcCodeCtxt -> Bool
|
|
160 | -isUserCodeCtxt UserCode = True
|
|
161 | -isUserCodeCtxt _ = False
|
|
162 | - |
|
163 | -isGeneratedCodeCtxt :: SrcCodeCtxt -> Bool
|
|
164 | -isGeneratedCodeCtxt UserCode = False
|
|
165 | -isGeneratedCodeCtxt _ = True |
... | ... | @@ -1234,8 +1234,8 @@ Other places that requires from the same treatment: |
1234 | 1234 | |
1235 | 1235 | -- Warn about certain types of values discarded in monadic bindings (#3263)
|
1236 | 1236 | warnDiscardedDoBindings :: LHsExpr GhcTc -> Type -> Type -> DsM ()
|
1237 | -warnDiscardedDoBindings rhs m_ty elt_ty
|
|
1238 | - = do { warn_unused <- woptM Opt_WarnUnusedDoBind
|
|
1237 | +warnDiscardedDoBindings rhs@(L rhs_loc _) m_ty elt_ty
|
|
1238 | + = putSrcSpanDsA rhs_loc $ do { warn_unused <- woptM Opt_WarnUnusedDoBind
|
|
1239 | 1239 | ; warn_wrong <- woptM Opt_WarnWrongDoBind
|
1240 | 1240 | ; when (warn_unused || warn_wrong) $
|
1241 | 1241 | do { fam_inst_envs <- dsGetFamInstEnvs
|
... | ... | @@ -189,8 +189,8 @@ tcExprSigma inst rn_expr |
189 | 189 | = do { (fun@(rn_fun,fun_ctxt), rn_args) <- splitHsApps rn_expr
|
190 | 190 | ; do_ql <- wantQuickLook rn_fun
|
191 | 191 | ; (tc_fun, fun_sigma) <- tcInferAppHead fun
|
192 | - ; code_ctxt <- getSrcCodeCtxt
|
|
193 | - ; let fun_orig = srcCodeCtxtCtOrigin rn_expr code_ctxt
|
|
192 | + ; code_orig <- getSrcCodeOrigin
|
|
193 | + ; let fun_orig = srcCodeOriginCtOrigin rn_expr code_orig
|
|
194 | 194 | ; (inst_args, app_res_sigma) <- tcInstFun do_ql inst fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
|
195 | 195 | ; tc_args <- tcValArgs do_ql rn_fun inst_args
|
196 | 196 | ; let tc_expr = rebuildHsApps (tc_fun, fun_ctxt) tc_args
|
... | ... | @@ -417,8 +417,8 @@ tcApp rn_expr exp_res_ty |
417 | 417 | ; let tc_head = (tc_fun, fun_loc)
|
418 | 418 | -- Step 3: Instantiate the function type (taking a quick look at args)
|
419 | 419 | ; do_ql <- wantQuickLook rn_fun
|
420 | - ; code_ctxt <- getSrcCodeCtxt
|
|
421 | - ; let fun_orig = srcCodeCtxtCtOrigin rn_fun code_ctxt
|
|
420 | + ; code_orig <- getSrcCodeOrigin
|
|
421 | + ; let fun_orig = srcCodeOriginCtOrigin rn_fun code_orig
|
|
422 | 422 | ; traceTc "tcApp:inferAppHead" $
|
423 | 423 | vcat [ text "tc_fun:" <+> ppr tc_fun
|
424 | 424 | , text "fun_sigma:" <+> ppr fun_sigma
|
... | ... | @@ -857,8 +857,7 @@ tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args |
857 | 857 | -- Rule IARG from Fig 4 of the QL paper:
|
858 | 858 | go1 pos acc fun_ty
|
859 | 859 | (EValArg { ea_arg = arg, ea_ctxt = ctxt } : rest_args)
|
860 | - = do { let herald | DoStmtOrigin <- fun_orig = ExpectedFunTySyntaxOp fun_orig tc_fun -- cf. RepPolyDoBind.hs
|
|
861 | - | otherwise = ExpectedFunTyArg (HsExprTcThing tc_fun) (unLoc arg)
|
|
860 | + = do { let herald = ExpectedFunTyArg pos (HsExprTcThing tc_fun) (unLoc arg)
|
|
862 | 861 | ; (wrap, arg_ty, res_ty) <-
|
863 | 862 | -- NB: matchActualFunTy does the rep-poly check.
|
864 | 863 | -- For example, suppose we have f :: forall r (a::TYPE r). a -> Int
|
... | ... | @@ -877,7 +876,7 @@ tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args |
877 | 876 | -- Make a fresh nus for each argument in rule IVAR
|
878 | 877 | new_arg_ty (L _ arg) i
|
879 | 878 | = do { arg_nu <- newOpenFlexiFRRTyVarTy $
|
880 | - FRRExpectedFunTy (ExpectedFunTyArg (HsExprTcThing tc_fun) arg) i
|
|
879 | + FRRExpectedFunTy (ExpectedFunTyArg i (HsExprTcThing tc_fun) arg) i
|
|
881 | 880 | -- Following matchActualFunTy, we create nu_i :: TYPE kappa_i[conc],
|
882 | 881 | -- thereby ensuring that the arguments have concrete runtime representations
|
883 | 882 |
... | ... | @@ -976,7 +976,7 @@ tcSynArgE orig op sigma_ty syn_ty thing_inside |
976 | 976 | -- fixed RuntimeRep, as needed to call mkWpFun.
|
977 | 977 | ; return (result, match_wrapper <.> fun_wrap) }
|
978 | 978 | where
|
979 | - herald = ExpectedFunTySyntaxOp orig op
|
|
979 | + herald = ExpectedFunTySyntaxOp 1 orig op
|
|
980 | 980 | |
981 | 981 | go rho_ty (SynType the_ty)
|
982 | 982 | = do { wrap <- tcSubTypePat orig GenSigCtxt the_ty rho_ty
|
... | ... | @@ -1005,7 +1005,7 @@ tcSynArgA orig op sigma_ty arg_shapes res_shape thing_inside |
1005 | 1005 | thing_inside (arg_results ++ res_results) (map scaledMult arg_tys ++ arg_res_mults)
|
1006 | 1006 | ; return (result, match_wrapper, arg_wrappers, res_wrapper) }
|
1007 | 1007 | where
|
1008 | - herald = ExpectedFunTySyntaxOp orig op
|
|
1008 | + herald = ExpectedFunTySyntaxOp (length arg_shapes) orig op
|
|
1009 | 1009 | |
1010 | 1010 | tc_syn_args_e :: [TcSigmaTypeFRR] -> [SyntaxOpType]
|
1011 | 1011 | -> ([TcSigmaTypeFRR] -> [Mult] -> TcM a)
|
... | ... | @@ -655,7 +655,7 @@ tcInferOverLit lit@(OverLit { ol_val = val |
655 | 655 | ; let
|
656 | 656 | thing = NameThing from_name
|
657 | 657 | mb_thing = Just thing
|
658 | - herald = ExpectedFunTyArg thing (HsLit noExtField hs_lit)
|
|
658 | + herald = ExpectedFunTyArg 1 thing (HsLit noExtField hs_lit)
|
|
659 | 659 | ; (wrap2, sarg_ty, res_ty) <- matchActualFunTy herald mb_thing (1, from_ty) from_ty
|
660 | 660 | |
661 | 661 | ; co <- unifyType mb_thing (hsLitType hs_lit) (scaledThing sarg_ty)
|
... | ... | @@ -118,7 +118,7 @@ tcFunBindMatches ctxt fun_name mult matches invis_pat_tys exp_ty |
118 | 118 | = assertPpr (funBindPrecondition matches) (pprMatches matches) $
|
119 | 119 | do { -- Check that they all have the same no of arguments
|
120 | 120 | arity <- checkArgCounts matches
|
121 | - |
|
121 | + ; let herald = ExpectedFunTyMatches arity (NameThing fun_name) matches
|
|
122 | 122 | ; traceTc "tcFunBindMatches 1" (ppr fun_name $$ ppr mult $$ ppr exp_ty $$ ppr arity)
|
123 | 123 | |
124 | 124 | ; (wrap_fun, r)
|
... | ... | @@ -138,7 +138,7 @@ tcFunBindMatches ctxt fun_name mult matches invis_pat_tys exp_ty |
138 | 138 | ; return (wrap_fun, r) }
|
139 | 139 | where
|
140 | 140 | mctxt = mkPrefixFunRhs (noLocA fun_name) noAnn
|
141 | - herald = ExpectedFunTyMatches (NameThing fun_name) matches
|
|
141 | + |
|
142 | 142 | |
143 | 143 | funBindPrecondition :: MatchGroup GhcRn (LHsExpr GhcRn) -> Bool
|
144 | 144 | funBindPrecondition (MG { mg_alts = L _ alts })
|
... | ... | @@ -698,7 +698,7 @@ tc_pat pat_ty penv ps_pat thing_inside = case ps_pat of |
698 | 698 | -- Note [View patterns and polymorphism]
|
699 | 699 | |
700 | 700 | -- Expression must be a function
|
701 | - ; let herald = ExpectedFunTyViewPat $ unLoc expr
|
|
701 | + ; let herald = ExpectedFunTyViewPat 1 $ unLoc expr
|
|
702 | 702 | ; (expr_wrap1, Scaled _mult inf_arg_ty, inf_res_sigma)
|
703 | 703 | <- matchActualFunTy herald (Just . HsExprRnThing $ unLoc expr) (1,expr_ty) expr_ty
|
704 | 704 | -- See Note [View patterns and polymorphism]
|
... | ... | @@ -17,7 +17,7 @@ import GHC.Hs.Extension |
17 | 17 | import GHC.Parser.Annotation ( LocatedN, SrcSpanAnnA )
|
18 | 18 | |
19 | 19 | import GHC.Tc.Errors.Types.PromotionErr ( TermLevelUseCtxt )
|
20 | -import GHC.Tc.Types.Origin ( CtOrigin, UserTypeCtxt, ExpectedFunTyOrigin )
|
|
20 | +import GHC.Tc.Types.Origin ( CtOrigin, UserTypeCtxt )
|
|
21 | 21 | import GHC.Tc.Utils.TcType ( TcType, TcTyCon )
|
22 | 22 | import GHC.Tc.Zonk.Monad ( ZonkM )
|
23 | 23 | |
... | ... | @@ -120,7 +120,7 @@ data ErrCtxtMsg |
120 | 120 | -- | In a function application.
|
121 | 121 | | FunAppCtxt !FunAppCtxtFunArg !Int
|
122 | 122 | -- | In a function call.
|
123 | - | FunTysCtxt !ExpectedFunTyOrigin !Type !Int !Int
|
|
123 | + | FunTysCtxt !CtOrigin !Type !Int !Int
|
|
124 | 124 | -- | In the result of a function call.
|
125 | 125 | | FunResCtxt !(HsExpr GhcTc) !Int !Type !Type !Int !Int
|
126 | 126 | -- | In the declaration of a type constructor.
|
... | ... | @@ -21,13 +21,14 @@ module GHC.Tc.Types.LclEnv ( |
21 | 21 | , setLclEnvTypeEnv
|
22 | 22 | , modifyLclEnvTcLevel
|
23 | 23 | |
24 | - , getLclEnvSrcCodeCtxt
|
|
25 | - , setLclEnvSrcCodeCtxt
|
|
26 | - , setLclCtxtSrcCodeCtxt
|
|
24 | + , getLclEnvSrcCodeOrigin
|
|
25 | + , setLclEnvSrcCodeOrigin
|
|
26 | + , setLclCtxtSrcCodeOrigin
|
|
27 | 27 | , lclEnvInGeneratedCode
|
28 | 28 | |
29 | 29 | , addLclEnvErrCtxt
|
30 | 30 | |
31 | + , ErrCtxtStack (..)
|
|
31 | 32 | , ArrowCtxt(..)
|
32 | 33 | , ThBindEnv
|
33 | 34 | , TcTypeEnv
|
... | ... | @@ -35,7 +36,7 @@ module GHC.Tc.Types.LclEnv ( |
35 | 36 | |
36 | 37 | import GHC.Prelude
|
37 | 38 | |
38 | -import GHC.Hs ( SrcCodeCtxt (..), isGeneratedCodeCtxt )
|
|
39 | +import GHC.Hs ( SrcCodeOrigin )
|
|
39 | 40 | import GHC.Tc.Utils.TcType ( TcLevel )
|
40 | 41 | import GHC.Tc.Errors.Types ( TcRnMessage )
|
41 | 42 | |
... | ... | @@ -90,11 +91,29 @@ data TcLclEnv -- Changes as we move inside an expression |
90 | 91 | tcl_errs :: TcRef (Messages TcRnMessage) -- Place to accumulate diagnostics
|
91 | 92 | }
|
92 | 93 | |
94 | + |
|
95 | +data ErrCtxtStack
|
|
96 | + = UserCodeCtxt {err_ctxt :: [ErrCtxt]}
|
|
97 | + | GeneratedCodeCtxt { src_code_origin :: SrcCodeOrigin
|
|
98 | + , err_ctxt :: [ErrCtxt] }
|
|
99 | + |
|
100 | +isGeneratedCodeCtxt :: ErrCtxtStack -> Bool
|
|
101 | +isGeneratedCodeCtxt UserCodeCtxt{} = False
|
|
102 | +isGeneratedCodeCtxt _ = True
|
|
103 | + |
|
104 | +get_src_code_origin :: ErrCtxtStack -> Maybe SrcCodeOrigin
|
|
105 | +get_src_code_origin (UserCodeCtxt{}) = Nothing
|
|
106 | +get_src_code_origin es = Just $ src_code_origin es
|
|
107 | + |
|
108 | +modify_err_ctxt_stack :: ([ErrCtxt] -> [ErrCtxt]) -> ErrCtxtStack -> ErrCtxtStack
|
|
109 | +modify_err_ctxt_stack f (UserCodeCtxt e) = UserCodeCtxt (f e)
|
|
110 | +modify_err_ctxt_stack _ c = c -- any updates on the err context in generated context should be ignored
|
|
111 | + |
|
112 | + |
|
93 | 113 | data TcLclCtxt
|
94 | 114 | = TcLclCtxt {
|
95 | 115 | tcl_loc :: RealSrcSpan, -- Source span
|
96 | - tcl_ctxt :: [ErrCtxt], -- Error context, innermost on top
|
|
97 | - tcl_in_gen_code :: SrcCodeCtxt,
|
|
116 | + tcl_ctxt :: ErrCtxtStack,
|
|
98 | 117 | tcl_tclvl :: TcLevel,
|
99 | 118 | tcl_bndrs :: TcBinderStack, -- Used for reporting relevant bindings,
|
100 | 119 | -- and for tidying type
|
... | ... | @@ -159,28 +178,28 @@ getLclEnvLoc :: TcLclEnv -> RealSrcSpan |
159 | 178 | getLclEnvLoc = tcl_loc . tcl_lcl_ctxt
|
160 | 179 | |
161 | 180 | getLclEnvErrCtxt :: TcLclEnv -> [ErrCtxt]
|
162 | -getLclEnvErrCtxt = tcl_ctxt . tcl_lcl_ctxt
|
|
181 | +getLclEnvErrCtxt = err_ctxt . tcl_ctxt . tcl_lcl_ctxt
|
|
163 | 182 | |
164 | 183 | setLclEnvErrCtxt :: [ErrCtxt] -> TcLclEnv -> TcLclEnv
|
165 | -setLclEnvErrCtxt ctxt = modifyLclCtxt (\env -> env { tcl_ctxt = ctxt })
|
|
184 | +setLclEnvErrCtxt ctxt = modifyLclCtxt (\env -> env { tcl_ctxt = modify_err_ctxt_stack (\ _ -> ctxt) (tcl_ctxt env) })
|
|
166 | 185 | |
167 | 186 | addLclEnvErrCtxt :: ErrCtxt -> TcLclEnv -> TcLclEnv
|
168 | -addLclEnvErrCtxt ctxt = modifyLclCtxt (\env -> env { tcl_ctxt = ctxt : (tcl_ctxt env) })
|
|
187 | +addLclEnvErrCtxt ec = modifyLclCtxt (\env -> env { tcl_ctxt = modify_err_ctxt_stack (\ctxt -> ec : ctxt) (tcl_ctxt env) })
|
|
169 | 188 | |
170 | -getLclEnvSrcCodeCtxt :: TcLclEnv -> SrcCodeCtxt
|
|
171 | -getLclEnvSrcCodeCtxt = tcl_in_gen_code . tcl_lcl_ctxt
|
|
189 | +getLclEnvSrcCodeOrigin :: TcLclEnv -> Maybe SrcCodeOrigin
|
|
190 | +getLclEnvSrcCodeOrigin = get_src_code_origin . tcl_ctxt . tcl_lcl_ctxt
|
|
172 | 191 | |
173 | -lclEnvInGeneratedCode :: TcLclEnv -> Bool
|
|
174 | -lclEnvInGeneratedCode = lclCtxtInGeneratedCode . tcl_lcl_ctxt
|
|
192 | +setLclEnvSrcCodeOrigin :: SrcCodeOrigin -> TcLclEnv -> TcLclEnv
|
|
193 | +setLclEnvSrcCodeOrigin o = modifyLclCtxt (setLclCtxtSrcCodeOrigin o)
|
|
175 | 194 | |
176 | -lclCtxtInGeneratedCode :: TcLclCtxt -> Bool
|
|
177 | -lclCtxtInGeneratedCode = isGeneratedCodeCtxt . tcl_in_gen_code
|
|
195 | +setLclCtxtSrcCodeOrigin :: SrcCodeOrigin -> TcLclCtxt -> TcLclCtxt
|
|
196 | +setLclCtxtSrcCodeOrigin o ctxt = ctxt { tcl_ctxt = GeneratedCodeCtxt o (err_ctxt $ tcl_ctxt ctxt) }
|
|
178 | 197 | |
179 | -setLclCtxtSrcCodeCtxt :: SrcCodeCtxt -> TcLclCtxt -> TcLclCtxt
|
|
180 | -setLclCtxtSrcCodeCtxt userOrGen env = env { tcl_in_gen_code = userOrGen }
|
|
198 | +lclCtxtInGeneratedCode :: TcLclCtxt -> Bool
|
|
199 | +lclCtxtInGeneratedCode = isGeneratedCodeCtxt . tcl_ctxt
|
|
181 | 200 | |
182 | -setLclEnvSrcCodeCtxt :: SrcCodeCtxt -> TcLclEnv -> TcLclEnv
|
|
183 | -setLclEnvSrcCodeCtxt userOrGen = modifyLclCtxt (\ctxt -> setLclCtxtSrcCodeCtxt userOrGen ctxt)
|
|
201 | +lclEnvInGeneratedCode :: TcLclEnv -> Bool
|
|
202 | +lclEnvInGeneratedCode = lclCtxtInGeneratedCode . tcl_lcl_ctxt
|
|
184 | 203 | |
185 | 204 | getLclEnvBinderStack :: TcLclEnv -> TcBinderStack
|
186 | 205 | getLclEnvBinderStack = tcl_bndrs . tcl_lcl_ctxt
|
... | ... | @@ -19,7 +19,7 @@ module GHC.Tc.Types.Origin ( |
19 | 19 | |
20 | 20 | -- * CtOrigin
|
21 | 21 | CtOrigin(..), exprCtOrigin, lexprCtOrigin, matchesCtOrigin, grhssCtOrigin,
|
22 | - srcCodeCtxtCtOrigin,
|
|
22 | + srcCodeOriginCtOrigin,
|
|
23 | 23 | isVisibleOrigin, toInvisibleOrigin,
|
24 | 24 | pprCtOrigin, isGivenOrigin, isWantedWantedFunDepOrigin,
|
25 | 25 | isWantedSuperclassOrigin,
|
... | ... | @@ -45,7 +45,7 @@ module GHC.Tc.Types.Origin ( |
45 | 45 | FRRArrowContext(..), pprFRRArrowContext,
|
46 | 46 | |
47 | 47 | -- ** ExpectedFunTy FixedRuntimeRepOrigin
|
48 | - ExpectedFunTyOrigin(..), pprExpectedFunTyOrigin, pprExpectedFunTyHerald,
|
|
48 | + pprExpectedFunTyHerald,
|
|
49 | 49 | |
50 | 50 | -- * InstanceWhat
|
51 | 51 | InstanceWhat(..), SafeOverlapping
|
... | ... | @@ -653,6 +653,62 @@ data CtOrigin |
653 | 653 | | AmbiguityCheckOrigin UserTypeCtxt
|
654 | 654 | | ImplicitLiftOrigin HsImplicitLiftSplice
|
655 | 655 | |
656 | + | ExpansionOrigin SrcCodeOrigin -- This is due to an expansion of the original thing given by SrcCodeOrigin
|
|
657 | + |
|
658 | + |
|
659 | + |
|
660 | + -- | A rebindable syntax operator is expected to have a function type.
|
|
661 | + --
|
|
662 | + -- Test cases for representation-polymorphism checks:
|
|
663 | + -- RepPolyDoBind, RepPolyDoBody{1,2}, RepPolyMc{Bind,Body,Guard}, RepPolyNPlusK
|
|
664 | + | forall (p :: Pass)
|
|
665 | + . (OutputableBndrId p)
|
|
666 | + => ExpectedFunTySyntaxOp Int
|
|
667 | + !CtOrigin !(HsExpr (GhcPass p))
|
|
668 | + -- ^ rebindable syntax operator
|
|
669 | + |
|
670 | + -- | A view pattern must have a function type.
|
|
671 | + --
|
|
672 | + -- Test cases for representation-polymorphism checks:
|
|
673 | + -- RepPolyBinder
|
|
674 | + | ExpectedFunTyViewPat Int
|
|
675 | + !(HsExpr GhcRn)
|
|
676 | + -- ^ function used in the view pattern
|
|
677 | + |
|
678 | + -- | Need to be able to extract an argument type from a function type.
|
|
679 | + --
|
|
680 | + -- Test cases for representation-polymorphism checks:
|
|
681 | + -- RepPolyApp
|
|
682 | + | forall (p :: Pass)
|
|
683 | + . Outputable (HsExpr (GhcPass p)) => ExpectedFunTyArg
|
|
684 | + Int
|
|
685 | + -- ^ Argument number
|
|
686 | + !TypedThing
|
|
687 | + -- ^ function
|
|
688 | + !(HsExpr (GhcPass p))
|
|
689 | + -- ^ argument
|
|
690 | + |
|
691 | + -- | Ensure that a function defined by equations indeed has a function type
|
|
692 | + -- with the appropriate number of arguments.
|
|
693 | + --
|
|
694 | + -- Test cases for representation-polymorphism checks:
|
|
695 | + -- RepPolyBinder, RepPolyRecordPattern, RepPolyWildcardPattern
|
|
696 | + | ExpectedFunTyMatches Int
|
|
697 | + !TypedThing
|
|
698 | + -- ^ name of the function
|
|
699 | + !(MatchGroup GhcRn (LHsExpr GhcRn))
|
|
700 | + -- ^ equations
|
|
701 | + |
|
702 | + -- | Ensure that a lambda abstraction has a function type.
|
|
703 | + --
|
|
704 | + -- Test cases for representation-polymorphism checks:
|
|
705 | + -- RepPolyLambda, RepPolyMatch
|
|
706 | + | ExpectedFunTyLam HsLamVariant
|
|
707 | + !(HsExpr GhcRn)
|
|
708 | + -- ^ the entire lambda-case expression
|
|
709 | + |
|
710 | + |
|
711 | + |
|
656 | 712 | data NonLinearPatternReason
|
657 | 713 | = LazyPatternReason
|
658 | 714 | | GeneralisedPatternReason
|
... | ... | @@ -737,7 +793,7 @@ exprCtOrigin (HsAppType _ e1 _) = lexprCtOrigin e1 |
737 | 793 | exprCtOrigin (OpApp _ _ op _) = lexprCtOrigin op
|
738 | 794 | exprCtOrigin (NegApp _ e _) = lexprCtOrigin e
|
739 | 795 | exprCtOrigin (HsPar _ e) = lexprCtOrigin e
|
740 | -exprCtOrigin (HsProjection _ _) = SectionOrigin
|
|
796 | +exprCtOrigin e@(HsProjection _ _) = ExpansionOrigin (OrigExpr e)
|
|
741 | 797 | exprCtOrigin (SectionL _ _ _) = SectionOrigin
|
742 | 798 | exprCtOrigin (SectionR _ _ _) = SectionOrigin
|
743 | 799 | exprCtOrigin (ExplicitTuple {}) = Shouldn'tHappenOrigin "explicit tuple"
|
... | ... | @@ -763,18 +819,14 @@ exprCtOrigin (HsHole _) = Shouldn'tHappenOrigin "hole expression" |
763 | 819 | exprCtOrigin (HsForAll {}) = Shouldn'tHappenOrigin "forall telescope" -- See Note [Types in terms]
|
764 | 820 | exprCtOrigin (HsQual {}) = Shouldn'tHappenOrigin "constraint context" -- See Note [Types in terms]
|
765 | 821 | exprCtOrigin (HsFunArr {}) = Shouldn'tHappenOrigin "function arrow" -- See Note [Types in terms]
|
766 | -exprCtOrigin (XExpr (ExpandedThingRn o _)) = srcCodeOriginCtOrigin o
|
|
822 | +exprCtOrigin (XExpr (ExpandedThingRn o _)) = ExpansionOrigin o
|
|
767 | 823 | exprCtOrigin (XExpr (PopErrCtxt e)) = exprCtOrigin e
|
768 | 824 | exprCtOrigin (XExpr (HsRecSelRn f)) = OccurrenceOfRecSel (foExt f)
|
769 | 825 | |
770 | -srcCodeOriginCtOrigin :: SrcCodeOrigin -> CtOrigin
|
|
771 | -srcCodeOriginCtOrigin (OrigExpr e) = exprCtOrigin e
|
|
772 | -srcCodeOriginCtOrigin (OrigStmt{}) = DoStmtOrigin
|
|
773 | -srcCodeOriginCtOrigin (OrigPat p) = DoPatOrigin p
|
|
774 | 826 | |
775 | -srcCodeCtxtCtOrigin :: HsExpr GhcRn -> SrcCodeCtxt -> CtOrigin
|
|
776 | -srcCodeCtxtCtOrigin e UserCode = exprCtOrigin e
|
|
777 | -srcCodeCtxtCtOrigin _ (GeneratedCode e) = srcCodeOriginCtOrigin e
|
|
827 | +srcCodeOriginCtOrigin :: HsExpr GhcRn -> Maybe SrcCodeOrigin -> CtOrigin
|
|
828 | +srcCodeOriginCtOrigin e Nothing = exprCtOrigin e
|
|
829 | +srcCodeOriginCtOrigin _ (Just e) = ExpansionOrigin e
|
|
778 | 830 | |
779 | 831 | -- | Extract a suitable CtOrigin from a MatchGroup
|
780 | 832 | matchesCtOrigin :: MatchGroup GhcRn (LHsExpr GhcRn) -> CtOrigin
|
... | ... | @@ -800,6 +852,14 @@ pprCtOrigin :: CtOrigin -> SDoc |
800 | 852 | pprCtOrigin (GivenOrigin sk)
|
801 | 853 | = ctoHerald <+> ppr sk
|
802 | 854 | |
855 | +pprCtOrigin (ExpansionOrigin o)
|
|
856 | + = ctoHerald <+> what
|
|
857 | + where what :: SDoc
|
|
858 | + what = case o of
|
|
859 | + OrigStmt{} -> text "a do statement"
|
|
860 | + OrigExpr e -> pprCtO (exprCtOrigin e)
|
|
861 | + OrigPat p -> text "a pattern" <+> ppr p
|
|
862 | + |
|
803 | 863 | pprCtOrigin (GivenSCOrigin sk d blk)
|
804 | 864 | = vcat [ ctoHerald <+> pprSkolInfo sk
|
805 | 865 | , whenPprDebug (braces (text "given-sc:" <+> ppr d <> comma <> ppr blk)) ]
|
... | ... | @@ -912,9 +972,38 @@ pprCtOrigin (NonLinearPatternOrigin reason pat) |
912 | 972 | = hang (ctoHerald <+> text "a non-linear pattern" <+> quotes (ppr pat))
|
913 | 973 | 2 (pprNonLinearPatternReason reason)
|
914 | 974 | |
975 | +pprCtOrigin (ExpectedFunTySyntaxOp i orig op) =
|
|
976 | + vcat [ sep [ the_arg_of i
|
|
977 | + , text "the rebindable syntax operator"
|
|
978 | + , quotes (ppr op) ]
|
|
979 | + , nest 2 (ppr orig) ]
|
|
980 | +pprCtOrigin (ExpectedFunTyViewPat i expr) =
|
|
981 | + vcat [ the_arg_of i <+> text "the view pattern"
|
|
982 | + , nest 2 (ppr expr) ]
|
|
983 | +pprCtOrigin (ExpectedFunTyArg i fun arg) =
|
|
984 | + sep [ text "The" <+> speakNth i <+> text "argument"
|
|
985 | + , quotes (ppr arg)
|
|
986 | + , text "of"
|
|
987 | + , quotes (ppr fun) ]
|
|
988 | +pprCtOrigin (ExpectedFunTyMatches i fun (MG { mg_alts = L _ alts }))
|
|
989 | + | null alts
|
|
990 | + = the_arg_of i <+> quotes (ppr fun)
|
|
991 | + | otherwise
|
|
992 | + = text "The" <+> speakNth i <+> text "pattern in the equation" <> plural alts
|
|
993 | + <+> text "for" <+> quotes (ppr fun)
|
|
994 | +pprCtOrigin (ExpectedFunTyLam lam_variant _) = binder_of $ lamCaseKeyword lam_variant
|
|
995 | + |
|
915 | 996 | pprCtOrigin simple_origin
|
916 | 997 | = ctoHerald <+> pprCtO simple_origin
|
917 | 998 | |
999 | + |
|
1000 | +the_arg_of :: Int -> SDoc
|
|
1001 | +the_arg_of i = text "The" <+> speakNth i <+> text "argument of"
|
|
1002 | + |
|
1003 | +binder_of :: SDoc -> SDoc
|
|
1004 | +binder_of what = text "The binder of the" <+> what <+> text "expression"
|
|
1005 | + |
|
1006 | + |
|
918 | 1007 | -- | Short one-liners
|
919 | 1008 | pprCtO :: HasDebugCallStack => CtOrigin -> SDoc
|
920 | 1009 | pprCtO (OccurrenceOf name) = hsep [text "a use of", quotes (ppr name)]
|
... | ... | @@ -940,7 +1029,7 @@ pprCtO (ScOrigin (IsQC {}) _) = text "the head of a quantified constraint" |
940 | 1029 | pprCtO DerivClauseOrigin = text "the 'deriving' clause of a data type declaration"
|
941 | 1030 | pprCtO StandAloneDerivOrigin = text "a 'deriving' declaration"
|
942 | 1031 | pprCtO DefaultOrigin = text "a 'default' declaration"
|
943 | -pprCtO DoStmtOrigin = text "a do statement"
|
|
1032 | +pprCtO DoStmtOrigin = text "a do statement"
|
|
944 | 1033 | pprCtO MCompOrigin = text "a statement in a monad comprehension"
|
945 | 1034 | pprCtO ProcOrigin = text "a proc expression"
|
946 | 1035 | pprCtO ArrowCmdOrigin = text "an arrow command"
|
... | ... | @@ -983,6 +1072,14 @@ pprCtO (InstanceSigOrigin {}) = text "a type signature in an instance" |
983 | 1072 | pprCtO (AmbiguityCheckOrigin {}) = text "a type ambiguity check"
|
984 | 1073 | pprCtO (ImpedanceMatching {}) = text "combining required constraints"
|
985 | 1074 | pprCtO (NonLinearPatternOrigin _ pat) = hsep [text "a non-linear pattern" <+> quotes (ppr pat)]
|
1075 | +pprCtO (ExpansionOrigin (OrigPat p)) = hsep [text "a pattern" <+> quotes (ppr p)]
|
|
1076 | +pprCtO (ExpansionOrigin (OrigStmt{})) = text "a do statement"
|
|
1077 | +pprCtO (ExpansionOrigin (OrigExpr e)) = text "an expression" <+> ppr e
|
|
1078 | +pprCtO (ExpectedFunTySyntaxOp{}) = text "a rebindable syntax operator"
|
|
1079 | +pprCtO (ExpectedFunTyViewPat{}) = text "a view pattern"
|
|
1080 | +pprCtO (ExpectedFunTyArg{}) = text "a funtion head"
|
|
1081 | +pprCtO (ExpectedFunTyMatches{}) = text "a match statement"
|
|
1082 | +pprCtO (ExpectedFunTyLam{}) = text "a lambda expression"
|
|
986 | 1083 | |
987 | 1084 | pprNonLinearPatternReason :: HasDebugCallStack => NonLinearPatternReason -> SDoc
|
988 | 1085 | pprNonLinearPatternReason LazyPatternReason = parens (text "non-variable lazy pattern aren't linear")
|
... | ... | @@ -1195,7 +1292,7 @@ data FixedRuntimeRepContext |
1195 | 1292 | --
|
1196 | 1293 | -- See 'ExpectedFunTyOrigin' for more details.
|
1197 | 1294 | | FRRExpectedFunTy
|
1198 | - !ExpectedFunTyOrigin
|
|
1295 | + !CtOrigin -- !ExpectedFunTyOrigin
|
|
1199 | 1296 | !Int
|
1200 | 1297 | -- ^ argument position (1-indexed)
|
1201 | 1298 | |
... | ... | @@ -1228,11 +1325,10 @@ mkFRRUnboxedSum = FRRUnboxedSum |
1228 | 1325 | -- and is reported separately.
|
1229 | 1326 | pprFixedRuntimeRepContext :: FixedRuntimeRepContext -> SDoc
|
1230 | 1327 | pprFixedRuntimeRepContext (FRRRecordCon lbl _arg)
|
1231 | - = sep [ text "The field", quotes (ppr lbl)
|
|
1328 | + = sep [ text "The field", quotes (ppr lbl) -- TODO ANI: Where does this get used? Add missing test?
|
|
1232 | 1329 | , text "of the record constructor" ]
|
1233 | -pprFixedRuntimeRepContext (FRRRecordUpdate lbl _arg)
|
|
1234 | - = sep [ text "The record update at field"
|
|
1235 | - , quotes (ppr lbl) ]
|
|
1330 | +pprFixedRuntimeRepContext (FRRRecordUpdate lbl _)
|
|
1331 | + = sep [ text "The field", quotes (ppr lbl) ]
|
|
1236 | 1332 | pprFixedRuntimeRepContext (FRRBinder binder)
|
1237 | 1333 | = sep [ text "The binder"
|
1238 | 1334 | , quotes (ppr binder) ]
|
... | ... | @@ -1277,8 +1373,8 @@ pprFixedRuntimeRepContext FRRBindStmtGuard |
1277 | 1373 | = sep [ text "The body of the bind statement" ]
|
1278 | 1374 | pprFixedRuntimeRepContext (FRRArrow arrowContext)
|
1279 | 1375 | = pprFRRArrowContext arrowContext
|
1280 | -pprFixedRuntimeRepContext (FRRExpectedFunTy funTyOrig arg_pos)
|
|
1281 | - = pprExpectedFunTyOrigin funTyOrig arg_pos
|
|
1376 | +pprFixedRuntimeRepContext (FRRExpectedFunTy funTyOrig _)
|
|
1377 | + = pprCtOrigin funTyOrig
|
|
1282 | 1378 | |
1283 | 1379 | instance Outputable FixedRuntimeRepContext where
|
1284 | 1380 | ppr = pprFixedRuntimeRepContext
|
... | ... | @@ -1431,102 +1527,56 @@ instance Outputable FRRArrowContext where |
1431 | 1527 | -- Uses 'pprExpectedFunTyOrigin'.
|
1432 | 1528 | -- See 'FixedRuntimeRepContext' for the situations in which
|
1433 | 1529 | -- representation-polymorphism checks are performed.
|
1434 | -data ExpectedFunTyOrigin
|
|
1435 | - |
|
1436 | - -- | A rebindable syntax operator is expected to have a function type.
|
|
1437 | - --
|
|
1438 | - -- Test cases for representation-polymorphism checks:
|
|
1439 | - -- RepPolyDoBind, RepPolyDoBody{1,2}, RepPolyMc{Bind,Body,Guard}, RepPolyNPlusK
|
|
1440 | - = forall (p :: Pass)
|
|
1441 | - . (OutputableBndrId p)
|
|
1442 | - => ExpectedFunTySyntaxOp !CtOrigin !(HsExpr (GhcPass p))
|
|
1443 | - -- ^ rebindable syntax operator
|
|
1444 | - |
|
1445 | - -- | A view pattern must have a function type.
|
|
1446 | - --
|
|
1447 | - -- Test cases for representation-polymorphism checks:
|
|
1448 | - -- RepPolyBinder
|
|
1449 | - | ExpectedFunTyViewPat
|
|
1450 | - !(HsExpr GhcRn)
|
|
1451 | - -- ^ function used in the view pattern
|
|
1452 | - |
|
1453 | - -- | Need to be able to extract an argument type from a function type.
|
|
1454 | - --
|
|
1455 | - -- Test cases for representation-polymorphism checks:
|
|
1456 | - -- RepPolyApp
|
|
1457 | - | forall (p :: Pass)
|
|
1458 | - . Outputable (HsExpr (GhcPass p)) => ExpectedFunTyArg
|
|
1459 | - !TypedThing
|
|
1460 | - -- ^ function
|
|
1461 | - !(HsExpr (GhcPass p))
|
|
1462 | - -- ^ argument
|
|
1463 | - |
|
1464 | - -- | Ensure that a function defined by equations indeed has a function type
|
|
1465 | - -- with the appropriate number of arguments.
|
|
1466 | - --
|
|
1467 | - -- Test cases for representation-polymorphism checks:
|
|
1468 | - -- RepPolyBinder, RepPolyRecordPattern, RepPolyWildcardPattern
|
|
1469 | - | ExpectedFunTyMatches
|
|
1470 | - !TypedThing
|
|
1471 | - -- ^ name of the function
|
|
1472 | - !(MatchGroup GhcRn (LHsExpr GhcRn))
|
|
1473 | - -- ^ equations
|
|
1474 | - |
|
1475 | - -- | Ensure that a lambda abstraction has a function type.
|
|
1476 | - --
|
|
1477 | - -- Test cases for representation-polymorphism checks:
|
|
1478 | - -- RepPolyLambda, RepPolyMatch
|
|
1479 | - | ExpectedFunTyLam HsLamVariant
|
|
1480 | - !(HsExpr GhcRn)
|
|
1481 | - -- ^ the entire lambda-case expression
|
|
1482 | - |
|
1483 | -pprExpectedFunTyOrigin :: ExpectedFunTyOrigin
|
|
1484 | - -> Int -- ^ argument position (starting at 1)
|
|
1485 | - -> SDoc
|
|
1486 | -pprExpectedFunTyOrigin funTy_origin i =
|
|
1487 | - case funTy_origin of
|
|
1488 | - ExpectedFunTySyntaxOp orig op ->
|
|
1489 | - vcat [ sep [ the_arg_of
|
|
1490 | - , text "the rebindable syntax operator"
|
|
1491 | - , quotes (ppr op) ]
|
|
1492 | - , nest 2 (ppr orig) ]
|
|
1493 | - ExpectedFunTyViewPat expr ->
|
|
1494 | - vcat [ the_arg_of <+> text "the view pattern"
|
|
1495 | - , nest 2 (ppr expr) ]
|
|
1496 | - ExpectedFunTyArg fun arg ->
|
|
1497 | - sep [ text "The argument"
|
|
1498 | - , quotes (ppr arg)
|
|
1499 | - , text "of"
|
|
1500 | - , quotes (ppr fun) ]
|
|
1501 | - ExpectedFunTyMatches fun (MG { mg_alts = L _ alts })
|
|
1502 | - | null alts
|
|
1503 | - -> the_arg_of <+> quotes (ppr fun)
|
|
1504 | - | otherwise
|
|
1505 | - -> text "The" <+> speakNth i <+> text "pattern in the equation" <> plural alts
|
|
1506 | - <+> text "for" <+> quotes (ppr fun)
|
|
1507 | - ExpectedFunTyLam lam_variant _ -> binder_of $ lamCaseKeyword lam_variant
|
|
1508 | - where
|
|
1509 | - the_arg_of :: SDoc
|
|
1510 | - the_arg_of = text "The" <+> speakNth i <+> text "argument of"
|
|
1511 | 1530 | |
1512 | - binder_of :: SDoc -> SDoc
|
|
1513 | - binder_of what = text "The binder of the" <+> what <+> text "expression"
|
|
1514 | 1531 | |
1515 | -pprExpectedFunTyHerald :: ExpectedFunTyOrigin -> SDoc
|
|
1532 | +-- pprExpectedFunTyOrigin :: -- ExpectedFunTyOrigin
|
|
1533 | +-- -- -> Int -- ^ argument position (starting at 1)
|
|
1534 | +-- -> SDoc
|
|
1535 | +-- pprExpectedFunTyOrigin funTy_origin =
|
|
1536 | +-- case funTy_origin of
|
|
1537 | +-- ExpectedFunTySyntaxOp i orig op ->
|
|
1538 | +-- vcat [ sep [ the_arg_of
|
|
1539 | +-- , text "the rebindable syntax operator"
|
|
1540 | +-- , quotes (ppr op) ]
|
|
1541 | +-- , nest 2 (ppr orig) ]
|
|
1542 | +-- ExpectedFunTyViewPat i expr ->
|
|
1543 | +-- vcat [ the_arg_of <+> text "the view pattern"
|
|
1544 | +-- , nest 2 (ppr expr) ]
|
|
1545 | +-- ExpectedFunTyArg fun arg ->
|
|
1546 | +-- sep [ text "The argument"
|
|
1547 | +-- , quotes (ppr arg)
|
|
1548 | +-- , text "of"
|
|
1549 | +-- , quotes (ppr fun) ]
|
|
1550 | +-- ExpectedFunTyMatches i fun (MG { mg_alts = L _ alts })
|
|
1551 | +-- | null alts
|
|
1552 | +-- -> the_arg_of <+> quotes (ppr fun)
|
|
1553 | +-- | otherwise
|
|
1554 | +-- -> text "The" <+> speakNth i <+> text "pattern in the equation" <> plural alts
|
|
1555 | +-- <+> text "for" <+> quotes (ppr fun)
|
|
1556 | +-- ExpectedFunTyLam lam_variant _ -> binder_of $ lamCaseKeyword lam_variant
|
|
1557 | +-- where
|
|
1558 | +-- the_arg_of :: Int -> SDoc
|
|
1559 | +-- the_arg_of i = text "The" <+> speakNth i <+> text "argument of"
|
|
1560 | + |
|
1561 | +-- binder_of :: SDoc -> SDoc
|
|
1562 | +-- binder_of what = text "The binder of the" <+> what <+> text "expression"
|
|
1563 | + |
|
1564 | +pprExpectedFunTyHerald :: CtOrigin -> SDoc
|
|
1516 | 1565 | pprExpectedFunTyHerald (ExpectedFunTySyntaxOp {})
|
1517 | 1566 | = text "This rebindable syntax expects a function with"
|
1518 | 1567 | pprExpectedFunTyHerald (ExpectedFunTyViewPat {})
|
1519 | 1568 | = text "A view pattern expression expects"
|
1520 | -pprExpectedFunTyHerald (ExpectedFunTyArg fun _)
|
|
1569 | +pprExpectedFunTyHerald (ExpectedFunTyArg _ fun _)
|
|
1521 | 1570 | = sep [ text "The function" <+> quotes (ppr fun)
|
1522 | 1571 | , text "is applied to" ]
|
1523 | -pprExpectedFunTyHerald (ExpectedFunTyMatches fun (MG { mg_alts = L _ alts }))
|
|
1572 | +pprExpectedFunTyHerald (ExpectedFunTyMatches _ fun (MG { mg_alts = L _ alts }))
|
|
1524 | 1573 | = text "The equation" <> plural alts <+> text "for" <+> quotes (ppr fun) <+> hasOrHave alts
|
1525 | 1574 | pprExpectedFunTyHerald (ExpectedFunTyLam lam_variant expr)
|
1526 | 1575 | = sep [ text "The" <+> lamCaseKeyword lam_variant <+> text "expression"
|
1527 | 1576 | <+> quotes (pprSetDepth (PartWay 1) (ppr expr))
|
1528 | 1577 | -- The pprSetDepth makes the lambda abstraction print briefly
|
1529 | 1578 | , text "has" ]
|
1579 | +pprExpectedFunTyHerald orig = ppr (Shouldn'tHappenOrigin "pprExpectedFunTyHerald") <+> ppr orig
|
|
1530 | 1580 | |
1531 | 1581 | {- *******************************************************************
|
1532 | 1582 | * *
|
... | ... | @@ -58,7 +58,7 @@ module GHC.Tc.Utils.Monad( |
58 | 58 | addDependentFiles,
|
59 | 59 | |
60 | 60 | -- * Error management
|
61 | - getSrcCodeCtxt,
|
|
61 | + getSrcCodeOrigin,
|
|
62 | 62 | getSrcSpanM, setSrcSpan, setSrcSpanA, addLocM,
|
63 | 63 | inGeneratedCode, setInGeneratedCode,
|
64 | 64 | wrapLocM, wrapLocFstM, wrapLocFstMA, wrapLocSndM, wrapLocSndMA, wrapLocM_,
|
... | ... | @@ -400,8 +400,7 @@ initTcWithGbl hsc_env gbl_env loc do_this |
400 | 400 | tcl_lcl_ctxt = TcLclCtxt {
|
401 | 401 | tcl_loc = loc,
|
402 | 402 | -- tcl_loc should be over-ridden very soon!
|
403 | - tcl_in_gen_code = UserCode,
|
|
404 | - tcl_ctxt = [],
|
|
403 | + tcl_ctxt = UserCodeCtxt [],
|
|
405 | 404 | tcl_rdr = emptyLocalRdrEnv,
|
406 | 405 | tcl_th_ctxt = topLevel,
|
407 | 406 | tcl_th_bndrs = emptyNameEnv,
|
... | ... | @@ -978,21 +977,21 @@ setSrcSpan :: SrcSpan -> TcRn a -> TcRn a |
978 | 977 | -- See Note [Error contexts in generated code]
|
979 | 978 | -- for the tcl_in_gen_code manipulation
|
980 | 979 | setSrcSpan (RealSrcSpan loc _) thing_inside
|
981 | - = updLclCtxt (\env -> env { tcl_loc = loc, tcl_in_gen_code = UserCode })
|
|
980 | + = updLclCtxt (\env -> env { tcl_loc = loc, tcl_ctxt = UserCodeCtxt (err_ctxt $ tcl_ctxt env)})
|
|
982 | 981 | thing_inside
|
983 | 982 | |
984 | 983 | setSrcSpan (UnhelpfulSpan _) thing_inside
|
985 | 984 | = thing_inside
|
986 | 985 | |
987 | -getSrcCodeCtxt :: TcRn SrcCodeCtxt
|
|
988 | -getSrcCodeCtxt = getLclEnvSrcCodeCtxt <$> getLclEnv
|
|
986 | +getSrcCodeOrigin :: TcRn (Maybe SrcCodeOrigin)
|
|
987 | +getSrcCodeOrigin = getLclEnvSrcCodeOrigin <$> getLclEnv
|
|
989 | 988 | |
990 | 989 | -- | Mark the inner computation as being done inside generated code.
|
991 | 990 | --
|
992 | 991 | -- See Note [Error contexts in generated code]
|
993 | 992 | setInGeneratedCode :: SrcCodeOrigin -> TcRn a -> TcRn a
|
994 | -setInGeneratedCode scOrig thing_inside =
|
|
995 | - updLclCtxt (setLclCtxtSrcCodeCtxt (GeneratedCode scOrig)) thing_inside
|
|
993 | +setInGeneratedCode sco thing_inside =
|
|
994 | + updLclCtxt (setLclCtxtSrcCodeOrigin sco) thing_inside
|
|
996 | 995 | |
997 | 996 | setSrcSpanA :: EpAnn ann -> TcRn a -> TcRn a
|
998 | 997 | setSrcSpanA l = setSrcSpan (locA l)
|
... | ... | @@ -135,7 +135,7 @@ import Data.Traversable (for) |
135 | 135 | --
|
136 | 136 | -- See Note [Return arguments with a fixed RuntimeRep].
|
137 | 137 | matchActualFunTy
|
138 | - :: ExpectedFunTyOrigin
|
|
138 | + :: CtOrigin
|
|
139 | 139 | -- ^ See Note [Herald for matchExpectedFunTys]
|
140 | 140 | -> Maybe TypedThing
|
141 | 141 | -- ^ The thing with type TcSigmaType
|
... | ... | @@ -241,7 +241,7 @@ Ugh! |
241 | 241 | -- INVARIANT: the returned argument types all have a syntactically fixed RuntimeRep
|
242 | 242 | -- in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.
|
243 | 243 | -- See Note [Return arguments with a fixed RuntimeRep].
|
244 | -matchActualFunTys :: ExpectedFunTyOrigin -- ^ See Note [Herald for matchExpectedFunTys]
|
|
244 | +matchActualFunTys :: CtOrigin -- ^ See Note [Herald for matchExpectedFunTys]
|
|
245 | 245 | -> CtOrigin
|
246 | 246 | -> Arity
|
247 | 247 | -> TcSigmaType
|
... | ... | @@ -776,7 +776,7 @@ Example: |
776 | 776 | -- in the sense of Note [Fixed RuntimeRep] in GHC.Tc.Utils.Concrete.
|
777 | 777 | -- See Note [Return arguments with a fixed RuntimeRep].
|
778 | 778 | matchExpectedFunTys :: forall a.
|
779 | - ExpectedFunTyOrigin -- See Note [Herald for matchExpectedFunTys]
|
|
779 | + CtOrigin -- See Note [Herald for matchExpectedFunTys]
|
|
780 | 780 | -> UserTypeCtxt
|
781 | 781 | -> VisArity
|
782 | 782 | -> ExpSigmaType
|
... | ... | @@ -905,19 +905,19 @@ matchExpectedFunTys herald ctx arity (Check top_ty) thing_inside |
905 | 905 | ; co <- unifyType Nothing (mkScaledFunTys more_arg_tys res_ty) fun_ty
|
906 | 906 | ; return (mkWpCastN co, result) }
|
907 | 907 | |
908 | -new_infer_arg_ty :: ExpectedFunTyOrigin -> Int -> TcM (Scaled ExpSigmaTypeFRR)
|
|
908 | +new_infer_arg_ty :: CtOrigin -> Int -> TcM (Scaled ExpSigmaTypeFRR)
|
|
909 | 909 | new_infer_arg_ty herald arg_pos -- position for error messages only
|
910 | 910 | = do { mult <- newFlexiTyVarTy multiplicityTy
|
911 | 911 | ; inf_hole <- newInferExpTypeFRR (FRRExpectedFunTy herald arg_pos)
|
912 | 912 | ; return (mkScaled mult inf_hole) }
|
913 | 913 | |
914 | -new_check_arg_ty :: ExpectedFunTyOrigin -> Int -> TcM (Scaled TcType)
|
|
914 | +new_check_arg_ty :: CtOrigin -> Int -> TcM (Scaled TcType)
|
|
915 | 915 | new_check_arg_ty herald arg_pos -- Position for error messages only, 1 for first arg
|
916 | 916 | = do { mult <- newFlexiTyVarTy multiplicityTy
|
917 | 917 | ; arg_ty <- newOpenFlexiFRRTyVarTy (FRRExpectedFunTy herald arg_pos)
|
918 | 918 | ; return (mkScaled mult arg_ty) }
|
919 | 919 | |
920 | -mkFunTysMsg :: ExpectedFunTyOrigin
|
|
920 | +mkFunTysMsg :: CtOrigin
|
|
921 | 921 | -> (VisArity, TcType)
|
922 | 922 | -> TidyEnv -> ZonkM (TidyEnv, ErrCtxtMsg)
|
923 | 923 | -- See Note [Reporting application arity errors]
|
1 | -T10662.hs:2:8: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)]
|
|
1 | + |
|
2 | +T10662.hs:3:3: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)]
|
|
2 | 3 | A do-notation statement discarded a result of type ‘String’
|
3 | 4 | Suggested fix:
|
4 | 5 | Suppress this warning by saying
|
5 | 6 | ‘_ <- return $ let a = "hello" in a’ |
6 | - |
1 | -T3263-1.hs:24:6: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)]
|
|
1 | + |
|
2 | +T3263-1.hs:25:3: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)]
|
|
2 | 3 | A do-notation statement discarded a result of type ‘Int’
|
3 | 4 | Suggested fix: Suppress this warning by saying ‘_ <- nonNullM’
|
4 | 5 | |
5 | -T3263-1.hs:34:6: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)]
|
|
6 | +T3263-1.hs:35:3: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)]
|
|
6 | 7 | A do-notation statement discarded a result of type ‘Int’
|
7 | 8 | Suggested fix: Suppress this warning by saying ‘_ <- nonNullM’ |
8 | - |
1 | -T3263-2.hs:24:6: warning: [GHC-08838] [-Wwrong-do-bind (in -Wdefault)]
|
|
1 | + |
|
2 | +T3263-2.hs:25:3: warning: [GHC-08838] [-Wwrong-do-bind (in -Wdefault)]
|
|
2 | 3 | A do-notation statement discarded a result of type ‘m Int’
|
3 | 4 | Suggested fix:
|
4 | 5 | Suppress this warning by saying ‘_ <- return (return 10 :: m Int)’
|
5 | 6 | |
6 | -T3263-2.hs:36:6: warning: [GHC-08838] [-Wwrong-do-bind (in -Wdefault)]
|
|
7 | +T3263-2.hs:37:3: warning: [GHC-08838] [-Wwrong-do-bind (in -Wdefault)]
|
|
7 | 8 | A do-notation statement discarded a result of type ‘m Int’
|
8 | 9 | Suggested fix:
|
9 | 10 | Suppress this warning by saying ‘_ <- return (return 10 :: m Int)’ |
10 | - |
1 | 1 | :load break029.hs
|
2 | 2 | :step f 3
|
3 | 3 | :step
|
4 | +:step
|
|
4 | 5 | y |
... | ... | @@ -13,8 +13,7 @@ RepPolyRecordUpdate.hs:7:35: error: [GHC-55287] |
13 | 13 | X a :: TYPE rep
|
14 | 14 | |
15 | 15 | RepPolyRecordUpdate.hs:13:9: error: [GHC-55287]
|
16 | - • The argument ‘fld’ of ‘MkX’
|
|
17 | - does not have a fixed runtime representation.
|
|
16 | + • The field ‘fld’ does not have a fixed runtime representation.
|
|
18 | 17 | Its type is:
|
19 | 18 | a0 :: TYPE rep0
|
20 | 19 | When unifying:
|