Pattern mach checking for Rationals seems to be broken.
Consider this code:
foo_small :: ()
foo_small = case 2e2 :: Rational of
2e1 -> () -- redundant
2e2 -> ()
-- Large exponents are handled differently so we have an extra check.
foo :: ()
foo = case 2e102 :: Rational of
2e101 -> () -- redundant
2e102 -> ()
-- Any literal of type T will desugar to the same value MkT.
-- Eg. (1.0 :: T) == MkT
data T = MkT deriving Eq
instance Num T where
instance Fractional T where
fromRational _ = MkT
-- Large exponents are handled differently so we have an extra check.
bar :: ()
bar = case 2e102 :: T {- == MkT #-} of
2e101 -> () -- not redundant, pattern evaluates to MkT
2e102 -> () -- redundant, pattern also evaluates to MkT
baz :: ()
baz = case 2e1 :: T of
2e1 -> () -- not redundant, pattern evaluates to MkT
2e2 -> () -- redundant, pattern also evaluates to MkT
This currently (ghc-8.10, but also HEAD) only recognizes the last pattern match as redundant:
ghc T15646a.hs -O -Wall
[1 of 1] Compiling T15646a ( T15646a.hs, T15646a.o ) [Optimisation flags changed]
T15646a.hs:34:3: warning: [-Woverlapping-patterns]
Pattern match is redundant
In a case alternative: 2e2 -> ...
|
34 | 2e2 -> () -- redundant, pattern also evaluates to MkT
| ^^^^^^^^^