WIP #9173: Better type mismatch error messages
The problem:
- improve type/kind mismatch error messages
- provide additional info about context in which type mismatch occurred.
Implementation details:
- Add an
SDoc
field to theCheck
constructor ofTcType.ExpType
. - In every
mkCheckExpType
, supply appropriate message. - Update
synKnownType
too, since it usesmkCheckExpType
under the hood. (?) - Add a new field
uo_context
toTypeEqOrigin
(of typeMaybe SDoc
) that will get the doc from theCheck
. Update every place where we make aTypeEqOrigin
. - Teach
TcErrors.mkExpectedActualMsg
to use this new info to produce better error messages.
Change breakdown by file:
-
- update
mk_wanted_extra
(insidemkEqErr1
)- change herald1/herald2, decide whether we need
msg1
)
- change herald1/herald2, decide whether we need
- update
mkExpectedActualMsg
- Rip out the special treatment of kinds (get rid of
msg5
) (?)
- Rip out the special treatment of kinds (get rid of
- update
-
- update
newOverloadedLit
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
newNonTrivialOverloadedLit
- supply appropriate context message to
synKnownType
- supply appropriate context message to
- update
-
- update
tcProc
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- udpate
tc_cmd
- supply appropriate context message to
mkCheckExpType
for:HsCmdCase
-
HsCmdIf
-- ordinaryif
-
HsCmdIf
-- rebindable syntax HsCmdArrApp
HsCmdApp
-
HsCmdLam
-- patterns and GRHSs
- supply appropriate context message to
- update
tcArrDoStmt
- supply appropriate context message to
mkCheckExpType
for:BindStmt
RecStmt
- supply appropriate context message to
- update
-
- update
tcLocalBinds
- supply appropriate context message to
mkCheckExpType
forHsIPBinds
case
- supply appropriate context message to
- update
mkCheckExpType
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- udpate
tcRhs
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
-
- update
tcPolyExpr
(tcPolyExprNC
)- supply appropriate context message to
mkCheckExpType
(?) - failing text - ado/ado002
- supply appropriate context message to
- update
tcExpr
for:NegApp
ExplicitList
HsIf
- update
tcExpr
- supply appropriate context message to
tcPolyExprNC
- supply appropriate context message to
- update
tcArg
- supply appropriate context message to
tcPolyExprNC
- supply appropriate context message to
- update
tcSynArgE
(update local functiongo
forSynFun
)- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- udpate
tcExprSig
- case
CompleteSig
- supply appropriate context message totcPolyExprNC
case- failing test - ghci/scripts/ghci051
- case
PartialSig
- supply appropriate context message totcPolyExprNC
case
- case
- update
tcTagToEnum
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
tcRecordField
- supply appropriate context message to
tcPolyExprNC
- supply appropriate context message to
- update
-
- add
uo_context
field toorigin
of typeTypeEqOrigin
incheckExpectedKindX
- add
-
- update
tcMatchesCase
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
tcGRHSsPat
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
tcDoStmts
- supply appropriate context message to
mkCheckExpType
- failing test - ado/ado002, ado/T13242a
- supply appropriate context message to
- update
tcGuardStmt
- supply appropriate context message to
mkCheckExpType
(2)
- supply appropriate context message to
- update
tcLcStmt
- supply appropriate context message to
mkCheckExpType
(4)
- supply appropriate context message to
- update
tcMcStmt
-
LastStmt
case - supply appropriate context message tomkCheckExpType
(2) -
BindStmt
case - supply appropriate context message tomkCheckExpType
(3) -
BodyStmt
case - supply appropriate context message tomkCheckExpType
(3) -
TransStmt
case - supply appropriate context message (mkCheckExpType
,synKnownType
) (5) -
ParStmt
case - supply appropriate context message (mkCheckExpType
,synKnownType
) (4)
-
- udpate
tcDoStmt
-
BindStmt
case - supply appropriate context message tomkCheckExpType
(3) -
ApplicativeStmt
- supply appropriate context message tomkCheckExpType
(2) -
BodyStmt
case - supply appropriate context message tomkCheckExpType
(2) -
RecStmt
case - supply appropriate context message (mkCheckExpType
,synKnownType
) (6)
-
- update
tcMonadFailOp
- supply appropriate context message (
mkCheckExpType
,synKnownType
) (2)
- supply appropriate context message (
- update
tcApplicativeStmts
- supply appropriate context message (
mkCheckExpType
,synKnownType
) (6)
- supply appropriate context message (
- update
-
- update
Check
pattern inreadExpType_maybe
- update
Check
pattern incheckingExpType_maybe
- update
Check
pattern incheckingExpType
- update
Check
pattern intauifyExpType
- update
Check
pattern inexpTypeToType
- update
-
- update
Check
pattern match intcPatBndr
- update
tc_pat
- supply appropriate context message to
mkCheckExpType
forAsPat
SigPat
-
ListPat
(3) TuplePat
SumPat
-
NPat
(3) -
NPlusKPat
(6)
- supply appropriate context message to
- update
tcConArg
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
-
- update
tcCheckPatSynDecl
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
-
- update
check_main
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- udpate
tcGhciStmts
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
-
- Add a
Maybe SDoc
field to theTypeEqOrigin
constructor ofCtOrigin
We will record there the aspect of the context that leads us to expect the "expected" type.
- Add a
-
- update
generateRuleConstraints
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
-
- update
tcPendingSplice
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
tcNestedSplice
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
tcTopSplice
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
runTopSplice
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
-
- Add an
SDoc
field to theCheck
constructor of anExpType
- Add an
-
- update
matchExpectedFunTys
(localgo
function)- get context from
Check
and give it tomkCheckExpType
-
FunTy
case - supply appropriate context message tomkCheckExpType
-
TyVarTy
case - supply appropriate context message tomkCheckExpType
(2)
- get context from
- udpate
tcSubTypeET
- get context from
Check
and give it tomkCheckExpType
- get context from
- udpate
addSubTypeCtxt
- supply appropriate context message to
mkCheckExpType
- supply appropriate context message to
- update
tcSubType_NC
- supply appropriate context message to
uo_context
ofTypeEqOrigin
- supply appropriate context message to
- update
tcSubTypeDS_NC_O
- supply appropriate context message to
uo_context
ofTypeEqOrigin
- supply appropriate context message to
- update
promoteTcType
- supply appropriate context message to
uo_context
ofTypeEqOrigin
(2)
- supply appropriate context message to
- update
tcSkolemiseET
- get context from
Check
and give it tomkCheckExpType
- get context from
- update
unifyType
- supply appropriate context message to
uo_context
ofTypeEqOrigin
- failing test - ado/ado002
- supply appropriate context message to
- update
unifyKind
- supply appropriate context message to
uo_context
ofTypeEqOrigin
- supply appropriate context message to
- update
matchExpectedFunKind
- supply appropriate context message to
uo_context
ofTypeEqOrigin
- failing test - dependent/should_fail/RAE_T32a
- supply appropriate context message to
- update
Miscellaneous notes/comments
* Ideally, the message will not mention any types, because there will be no chance to zonk them later.
Unresolved Questions
* in `TcExpr`, `tcPolyExprNC` uses `mkCheckExpType` but since the `NC` version
does not supple the context for the error, what do we want to supply to `mkCheckExpType`
in that case?
* Address message formatting in case of `type representation mismatch`
types of messages (e.g. tests in `deriving/` dir)