Commit 4025d66c authored by Joachim Breitner's avatar Joachim Breitner
Browse files

Elaborate "deriving" error messages

If "deriving (C)" fails, it will now, if possible, indicate which
particular field of which constructor has caused the failure. (This
fixes #8576)
parent 51bebb7c
......@@ -1049,9 +1049,11 @@ inferConstraints cls inst_tys rep_tc rep_tc_args
where
-- Constraints arising from the arguments of each constructor
con_arg_constraints cls' get_constrained_tys
= [ mkPredOrigin DerivOrigin (mkClassPred cls' [arg_ty])
= [ mkPredOrigin (DerivOriginDC data_con arg_n) (mkClassPred cls' [arg_ty])
| data_con <- tyConDataCons rep_tc,
arg_ty <- ASSERT( isVanillaDataCon data_con )
(arg_n, arg_ty) <-
ASSERT( isVanillaDataCon data_con )
zip [1..] $
get_constrained_tys $
dataConInstOrigArgTys data_con all_rep_tc_args,
not (isUnLiftedType arg_ty) ]
......
......@@ -1050,6 +1050,7 @@ mk_dict_err ctxt (ct, (matches, unifiers, safe_haskell))
drv_fixes = case orig of
DerivOrigin -> [drv_fix]
DerivOriginDC {} -> [drv_fix]
_ -> []
drv_fix = hang (ptext (sLit "use a standalone 'deriving instance' declaration,"))
......
......@@ -90,7 +90,7 @@ import TcEvidence
import Type
import Class ( Class )
import TyCon ( TyCon )
import DataCon ( DataCon, dataConUserType )
import DataCon ( DataCon, dataConUserType, dataConOrigArgTys )
import TcType
import Annotations
import InstEnv
......@@ -1779,6 +1779,8 @@ data CtOrigin
| ScOrigin -- Typechecking superclasses of an instance declaration
| DerivOrigin -- Typechecking deriving
| DerivOriginDC DataCon Int
-- Checking constraings arising from this data an and field index
| StandAloneDerivOrigin -- Typechecking stand-alone deriving
| DefaultOrigin -- Typechecking a default decl
| DoOrigin -- Arising from a do expression
......@@ -1816,6 +1818,10 @@ pprO TupleOrigin = ptext (sLit "a tuple")
pprO NegateOrigin = ptext (sLit "a use of syntactic negation")
pprO ScOrigin = ptext (sLit "the superclasses of an instance declaration")
pprO DerivOrigin = ptext (sLit "the 'deriving' clause of a data type declaration")
pprO (DerivOriginDC dc n) = hsep [ ptext (sLit "the"), speakNth n,
ptext (sLit "field of"), quotes (ppr dc),
parens (ptext (sLit "type") <+> quotes (ppr ty)) ]
where ty = dataConOrigArgTys dc !! (n-1)
pprO StandAloneDerivOrigin = ptext (sLit "a 'deriving' declaration")
pprO DefaultOrigin = ptext (sLit "a 'default' declaration")
pprO DoOrigin = ptext (sLit "a do statement")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment