mkSwitch without default case
Wolfgang Thaller
wolfgang.thaller at gmx.net
Fri Feb 6 13:24:20 EST 2004
I've tracked down another CG bug...
CgUtils.mkSwitch panics with a very informative "Prelude: head" when it
gets a switch that doesn't mention all alternatives in the range but
doesn't have a default case.
Other parts of the compiler leave out the default case on purpose when
they can prove that it can't happen (nested case expressions).
This disagreement about default cases leads to a panic when compiling
System.IO.Error.hs.
Here's a small module that reproduces the problem. The foobar function
prevents the two case expressions from being merged into one when -O is
used (without -O, the bug happens even when you leave 'foobar' out).
{-# OPTIONS -fno-implicit-prelude #-}
module Foo where
import GHC.Prim
data Y = X1 | X2 | X3 | X4 | X5 | X6 | X7 | X8
data X = WithY Y
| A1 | A2 | A3 | A4 | A5 | A6 | A7 | A8
foo A1 = X1
foo A2 = X2
foo A3 = X3
foo A4 = X4
foo A5 = X5
foo A6 = X6
foo A7 = X7
foo A8 = X8
foo (WithY _) = X1
bar (WithY x) = x
bar y = foobar (foo y)
{-# NOINLINE foobar #-}
foobar x = x
---
Cheers,
Wolfgang
More information about the Cvs-ghc
mailing list