[commit: ghc] master: Add a missing case to Lint's understanding of empty cases (1b282fc)
git at git.haskell.org
git at git.haskell.org
Fri Nov 22 20:05:12 UTC 2013
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/1b282fcc5e31cdb6dd1ccdb5a3dcf1b46ab3532b/ghc
>---------------------------------------------------------------
commit 1b282fcc5e31cdb6dd1ccdb5a3dcf1b46ab3532b
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Fri Nov 22 15:03:15 2013 +0000
Add a missing case to Lint's understanding of empty cases
case x:Int# of {}
is OK
>---------------------------------------------------------------
1b282fcc5e31cdb6dd1ccdb5a3dcf1b46ab3532b
compiler/coreSyn/CoreLint.lhs | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/compiler/coreSyn/CoreLint.lhs b/compiler/coreSyn/CoreLint.lhs
index 2b76a4a..f38a69a 100644
--- a/compiler/coreSyn/CoreLint.lhs
+++ b/compiler/coreSyn/CoreLint.lhs
@@ -550,8 +550,17 @@ checkCaseAlts :: CoreExpr -> OutType -> [CoreAlt] -> LintM ()
checkCaseAlts e ty alts =
do { checkL (all non_deflt con_alts) (mkNonDefltMsg e)
; checkL (increasing_tag con_alts) (mkNonIncreasingAltsMsg e)
- ; checkL (isJust maybe_deflt || not is_infinite_ty)
- (nonExhaustiveAltsMsg e) }
+
+ -- For types Int#, Word# with an infinite (well, large!) number of
+ -- possible values, there should usually be a DEFAULT case
+ -- But (see Note [Empty case alternatives] in CoreSyn) it's ok to
+ -- have *no* case alternatives.
+ -- In effect, this is a kind of partial test. I suppose it's possible
+ -- that we might *know* that 'x' was 1 or 2, in which case
+ -- case x of { 1 -> e1; 2 -> e2 }
+ -- would be fine.
+ ; checkL (isJust maybe_deflt || not is_infinite_ty || null alts)
+ (nonExhaustiveAltsMsg e) }
where
(con_alts, maybe_deflt) = findDefault alts
More information about the ghc-commits
mailing list