Skip to content

Commit 138a6e3

Browse files
sheafMarge Bot
authored andcommitted
Make mkCast assertion a bit clearer
This commit changes the assertion message that gets printed when one calls mkCast with a coercion whose kind does not match the type of the inner expression. I always found the assertion message a bit confusing, as it didn't clearly state what exactly was the error.
1 parent 46bb9a7 commit 138a6e3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

compiler/GHC/Core/Utils.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,13 @@ mkCast expr co
275275
= assertPpr (coercionRole co == Representational)
276276
(text "coercion" <+> ppr co <+> text "passed to mkCast"
277277
<+> ppr expr <+> text "has wrong role" <+> ppr (coercionRole co)) $
278-
warnPprTrace (not (coercionLKind co `eqType` exprType expr))
279-
"Trying to coerce" (text "(" <> ppr expr
280-
$$ text "::" <+> ppr (exprType expr) <> text ")"
281-
$$ ppr co $$ ppr (coercionType co)
282-
$$ callStackDoc) $
278+
warnPprTrace (not (coercionLKind co `eqType` exprType expr)) "Bad cast"
279+
(vcat [ text "Coercion LHS kind does not match enclosed expression type"
280+
, text "co:" <+> ppr co
281+
, text "coercionLKind:" <+> ppr (coercionLKind co)
282+
, text "exprType:" <+> ppr (exprType expr)
283+
, text "expr:" <+> ppr expr
284+
, callStackDoc ]) $
283285
case expr of
284286
Cast expr co2 -> mkCast expr (mkTransCo co2 co)
285287
Tick t expr -> Tick t (mkCast expr co)

0 commit comments

Comments
 (0)