#16129 closed bug (duplicate)

Incorrect non-exhaustive pattern warning with PatternSynonyms

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

Description

{-# language PatternSynonyms #-}
{-# language ViewPatterns #-}
{-# language TypeFamilies #-}

module Bug where

newtype GenLocated e = L e

newtype WithSourceText a = WithSourceText a

type StringLiteral = WithSourceText String

{-# COMPLETE StringLiteral #-}
pattern StringLiteral sl_s = WithSourceText sl_s

type family SrcSpanLess a

class HasSrcSpan a where
  decomposeSrcSpan :: a -> GenLocated (SrcSpanLess a)

type instance SrcSpanLess (GenLocated e) = e

instance HasSrcSpan (GenLocated a) where
  decomposeSrcSpan = id

bug :: GenLocated StringLiteral -> String
bug (decomposeSrcSpan->L (StringLiteral s)) = s

workaround :: GenLocated StringLiteral -> String
workaround (decomposeSrcSpan->L sl) = s
  where StringLiteral s = sl
$ ghci -Wincomplete-patterns Bug.hs
GHCi, version 8.7.20190103: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/simon/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )

Bug.hs:27:1: warning: [-Wincomplete-patterns]
    Pattern match(es) are non-exhaustive
    In an equation for ‘bug’: Patterns not matched: _
   |
27 | bug (decomposeSrcSpan->L (StringLiteral s)) = s
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ok, one module loaded.

I've been able to reproduce the issue with all versions of GHC >= 7.8.

Change History (2)

comment:1 Changed 11 months ago by RyanGlScott

Keywords: PatternSynonyms added
Summary: Incorrect non-exhaustive pattern warning with PatternSynonyms, ViewPatterns and TypeFamiliesIncorrect non-exhaustive pattern warning with PatternSynonyms

Here is a simpler version without ViewPatterns or TypeFamilies (they aren't essential to triggering this bug):

{-# LANGUAGE PatternSynonyms #-}
module Bug where

import Data.Functor.Identity

pattern Id :: a -> Identity a
pattern Id x = Identity x

bug, workaround1, workaround2 :: Identity a -> a
bug ia
  | Id a <- ia
  = a

workaround1 ia
  | let ia' = ia
  , Identity a <- ia'
  = a

workaround2 ia = a
  where Id a = ia

While this doesn't appear to be exactly the same bug as #15753, they feel related somehow.

comment:2 Changed 11 months ago by RyanGlScott

Resolution: duplicate
Status: newclosed

Urk, please ignore what I wrote in comment:1. I forgot to add a COMPLETE pragma on Id, and that makes the whole example invalid.

Here is my second attempt at a minimal example:

{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
module Bug where

import Data.Functor.Identity

{-# COMPLETE Id #-}
pattern Id :: a -> Identity a
pattern Id x = Identity x

class Hm a where
  hm :: a -> a
instance Hm (Identity a) where
  hm = id

bug, workaround1, workaround2 :: Identity a -> a
bug ia
  | Id a <- hm ia
  = a

workaround1 ia
  | let ia' = hm ia
  , Identity a <- ia'
  = a

workaround2 ia = a
  where Id a = hm ia

This time, I'm convinced that this is a duplicate of #15753, as this has the distinctive function-application-in-pattern-guard look that #15753 has. Closing as a duplicate.

Note: See TracTickets for help on using tickets.