Skip to content

Warn if a pattern guard obviates all others

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

module Main where

main :: IO ()
main = print $ foo (10 :: Int)
  where
    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.

Trac metadata
Trac field Value
Version 7.6.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information