- warn | length pats > maximum_output
- = pp_context ctx (ptext SLIT("are non-exhaustive"))
- 8 (hang (ptext SLIT("Patterns not recognized:"))
- 4 ((vcat $ map (ppr_incomplete_pats kind) (take maximum_output pats))
- $$ ptext SLIT("...")))
- | otherwise
- = pp_context ctx (ptext SLIT("are non-exhaustive"))
- 8 (hang (ptext SLIT("Patterns not recognized:"))
- 4 (vcat $ map (ppr_incomplete_pats kind) pats))
-
-pp_context NoMatchContext msg ind rest_of_msg = dontAddErrLoc "" (ptext SLIT("Some match(es)") <+> hang msg ind rest_of_msg)
-
-pp_context (DsMatchContext kind pats loc) msg ind rest_of_msg
- = addErrLocHdrLine loc message (hang (pp_match kind pats) ind rest_of_msg)
- where
- message = ptext SLIT("Pattern match(es)") <+> msg
-
- pp_match (FunMatch fun) pats
- = hsep [ptext SLIT("in the definition of function"), quotes (ppr fun)]
-
- pp_match CaseMatch pats
- = hang (ptext SLIT("in a group of case alternatives beginning:"))
- 4 (ppr_pats pats)
-
- pp_match PatBindMatch pats
- = hang (ptext SLIT("in a pattern binding:"))
- 4 (ppr_pats pats)
-
- pp_match LambdaMatch pats
- = hang (ptext SLIT("in a lambda abstraction:"))
- 4 (ppr_pats pats)
-
- pp_match DoBindMatch pats
- = hang (ptext SLIT("in a `do' pattern binding:"))
- 4 (ppr_pats pats)
-
- pp_match ListCompMatch pats
- = hang (ptext SLIT("in a `list comprension' pattern binding:"))
- 4 (ppr_pats pats)
-
- pp_match LetMatch pats
- = hang (ptext SLIT("in a `let' pattern binding:"))
- 4 (ppr_pats pats)
+ warn = pp_context ctx (ptext SLIT("are non-exhaustive"))
+ (\f -> hang (ptext SLIT("Patterns not matched:"))
+ 4 ((vcat $ map (ppr_incomplete_pats kind)
+ (take maximum_output pats))
+ $$ dots))
+
+ dots | length pats > maximum_output = ptext SLIT("...")
+ | otherwise = empty
+
+pp_context NoMatchContext msg rest_of_msg_fun
+ = dontAddErrLoc (ptext SLIT("Some match(es)") <+> hang msg 8 (rest_of_msg_fun id))
+
+pp_context (DsMatchContext kind pats loc) msg rest_of_msg_fun
+ = addWarnLocHdrLine loc
+ (ptext SLIT("Pattern match(es)") <+> msg)
+ (sep [ppr_match <> char ':', nest 4 (rest_of_msg_fun pref)])
+ where
+ (ppr_match, pref)
+ = case kind of
+ FunRhs fun -> (pprMatchContext kind, \ pp -> ppr fun <+> pp)
+ other -> (pprMatchContext kind <+> ppr_pats pats, \ pp -> pp)