Opened 6 years ago

Closed 4 years ago

Last modified 19 months ago

#8494 closed feature request (duplicate)

Warn if a pattern guard obviates all others

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


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 (4)

comment:1 Changed 6 years 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 6 years 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.

comment:3 Changed 4 years ago by thomie

Resolution: duplicate
Status: newclosed

Because the existence of duplicate tickets makes doing a BugSweep of the bug tracker more cumbersome, I'm closing these tickets as duplicate. Don't worry, they're still listed on PatternMatchCheck, and will hopefully all be addressed by the work on #595 ("Overhaul GHC's overlapping/non-exhaustive pattern checking").

comment:4 Changed 19 months ago by simonpj

Keywords: PatternMatchWarnings added
Note: See TracTickets for help on using tickets.