Opened 2 years ago

Closed 2 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: 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 (3)

comment:1 Changed 2 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 2 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 2 months ago by thomie

  • Resolution set to duplicate
  • Status changed from new to closed

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").

Note: See TracTickets for help on using tickets.