Opened 21 months ago

Last modified 21 months ago

#8494 new feature request

Warn if a pattern guard obviates all others

Reported by: JohnWiegley Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:


The following code, when compiled with -Wall, gives no warnings:

module Main where

main :: IO ()
main = print $ foo (10 :: Int)
    foo x
        | True = (20 :: Int)
        | x == 10 = (30 :: Int)

I would expect that since the pattern guard | True obviates the following guards, that it would warn about unreachable code. There was a bug in my code today which I tracked down to a code transposition that would have been easily spotted with such a warning.

Change History (2)

comment:1 Changed 21 months ago by hvr

Are you just interested in warning for the case of a reduced constant expression (such as True)? Or shall the compiler warn about dead code in general as soon as it is detected (in the case above, when compiling with -O, the following guards are optimized away when looking at Core)?

comment:2 Changed 21 months ago by JohnWiegley

The ticket is only about the case of reduced constant expressions, although dead code in general would be interesting to know about.

Note: See TracTickets for help on using tickets.