
#10746: No non-exhaustive pattern match warning given for empty case analysis -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: | PatternMatchWarnings Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #7669, #11806 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:15 gkaracha]:
Replying to [comment:14 dfeuer]: All the related tickets give me the impression that it is expected for `f` to be non-exhaustive and `g` to be exhaustive, which is not in accordance with Haskell's operational semantics. {{{#!hs f :: Int -> a f x = case x of {}
g :: Void -> a g x = case x of {} }}}
Unless you force `x` in another way, both `case x of {}` are equally non-exhaustive.
It seems your argument may be valid, but your premise is false! Using GHCi 7.10.3, {{{#!hs Prelude> :set -XEmptyCase -XEmptyDataDecls Prelude> data Void Prelude> let absurd :: Void -> a; absurd x = case x of Prelude> absurd (error "Really?") *** Exception: Really? }}} As you can see, the scrutinee is forced, producing the desired exception, ''not'' a pattern match failure. This is explained in the note on "Empty case alternatives" in `compiler/deSugar/Match.hs`:
The list of `EquationInfo` can be empty, arising from
`case x of {}` or `\case {}`
In that situation we desugar to
`case x of { _ -> error "pattern match failure" }`
The ''desugarer'' isn't certain whether there really should be no alternatives, so it adds a default case, as it always does. A later pass may remove it if it's inaccessible. (See also Note [Empty case alternatives] in `CoreSyn`.)
We do ''not'' desugar simply to
`error "empty case"`
or some such, because `x` might be bound to `(error "hello")`, in which case we want to see that `"hello"` exception, not `(error "empty case")`.
Note that in the above text,
`case x of { _ -> error "pattern match failure" }`
represents a ''Core'' `case` expression, not a ''Haskell'' case expression, so it always forces its scrutinee, regardless of what patterns it may or may not contain. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10746#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler