Opened 2 years ago

Closed 20 months ago

#10339 closed bug (duplicate)

PatternSynonyms confuse exhaustiveness check

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

Description

I just noticed some odd behaviour when (ab)using pattern synonyms in the following code (whose style I don't really endorse):

{-# LANGUAGE PatternSynonyms, LambdaCase #-}

module PatSyn1 where

import System.Directory (doesFileExist)

pattern Found    = True
pattern NotFound = False

readConfigFile :: FilePath -> IO ()
readConfigFile filePath = doesFileExist filePath >>= \case
    Found    -> putStrLn =<< readFile filePath
    NotFound -> putStrLn "File does not exist."


pattern Void = ()

foo :: () -> ()
foo Void = ()

Results in

/home/hvr/Haskell/PatSyn1.hs:(11,54)-(13,47): Warning:
    Pattern match(es) are non-exhaustive
    In a case alternative: Patterns not matched: _

/home/hvr/Haskell/PatSyn1.hs:19:1-13: Warning:
    Pattern match(es) are non-exhaustive
    In an equation for ‘foo’: Patterns not matched: _

Change History (3)

comment:1 Changed 2 years ago by hvr

Version: 7.10.17.8.1

This occurs since GHC 7.8 (when pattern synonyms were introduced), up to GHC HEAD

comment:2 Changed 20 months ago by wrl314

Another example showing same problem with simple unidirectional pattern synonym:

data Foo2 = Foo2 Int String

pattern F a <- Foo2 a _

blah :: Foo2 -> Int
blah (F a) = a + 1

Result:

Warning: Pattern match(es) are non-exhaustive
In an equation for ‘blah’: Patterns not matched: _

comment:3 Changed 20 months ago by cactus

Keywords: PatternSynonyms added
Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.