[GHC] #11806: GHC does not warn for mistakenly empty case
GHC
ghc-devs at haskell.org
Sat Apr 9 13:01:30 UTC 2016
#11806: GHC does not warn for mistakenly empty case
-------------------------------------+-------------------------------------
Reporter: dfeuer | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.10.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: GHC accepts | Unknown/Multiple
invalid program | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by gkaracha):
Replying to [ticket:11806 dfeuer]:
> {{{#!hs
> {-# LANGUAGE EmptyCase #-}
> {-# OPTIONS_GHC -Wall -fwarn-incomplete-uni-patterns #-}
>
> oops :: Int -> a
> oops x = case x of {}
> }}}
>
> Since `Int` is inhabited, I would expect a warning, but I get none.
Since empty case is typically used in situations where programmers want
GHC to see an absurdity, this seems most unfortunate.
Indeed. Yet, I feel like there is a big misconception here, from the you
said
> Since `Int` is inhabited
It is indeed inhabited, but **like any other type in Haskell**, where
every type is inhabited. That is, for the following (see #11390) a warning
should also be expected:
{{{#!hs
silly1 :: Void -> Void
silly1 x = case x of {}
}}}
There have been separate discussions on this (see related tickets #10746,
#7669, #11390) and I think that we have a design choice to make here.
Unless you force the argument in some other way like:
{{{#!hs
silly2 :: Void -> Void
silly2 x = x `seq` case x of {}
}}}
or
{{{#!hs
silly3 :: Void -> Void
silly3 (!x) = case x of {}
}}}
then it is indeed non-exhaustive. This means that in almost all cases, an
empty case expression will issue a warning (which I think is the right
thing to do).
Of course, in `silly2` and `silly3` the warning is too conservative but
remember that type inhabitation is undecidable. Hence, I see two choices
here. We can:
1. Always issue a non-exhaustive warning for empty case expressions, or
2. Never issue a non-exhaustive warning for empty case expressions.
I am pointing this out because before #7669 we would issue the warning you
seek here and it has been intentionally changed.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11806#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list