Deriving Show with -XEmptyDataDeriving cases on the wrong argument
Running this program in GHC 8.4.1-alpha:
{-# LANGUAGE EmptyDataDeriving #-}
{-# OPTIONS_GHC -ddump-deriv #-}
module Main (main) where
data Empty deriving Show
loop :: Empty
loop = let x = x in x
main :: IO ()
main = print loop
One would expect this to loop infinitely at runtime, but in practice, that is not the case:
$ /opt/ghc/8.4.1/bin/runghc Bug.hs
==================== Derived instances ====================
Derived class instances:
instance GHC.Show.Show Main.Empty where
GHC.Show.showsPrec z_a1Iu = case z_a1Iu of
Derived type family instances:
==================== Filling in method body ====================
GHC.Show.Show [Main.Empty]
GHC.Show.show = GHC.Show.$dmshow @(Main.Empty)
==================== Filling in method body ====================
GHC.Show.Show [Main.Empty]
GHC.Show.showList = GHC.Show.$dmshowList @(Main.Empty)
Bug.hs: Bug.hs:5:21-24: Non-exhaustive patterns in case
The -ddump-deriv output reveals why: the showsPrec implementation for Empty is casing on the //precedence// argument, not the actual value of type Empty! This results in the non-exhaustive patterns error.
This is my fault, so I'll prepare a fix :)
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.4.1-alpha1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | high |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |