Admin message

Due to a large amount of spam we do not allow new users to create repositories, they are "external" users. If you are a new user and want to create a repository, for example for forking GHC, open a new issue on ghc/ghc using the "get-verified" issue template

Take exhaustiveness checking into consideration when using MonadFailDesugaring
Consider the following code: ```hs import Data.List.NonEmpty (NonEmpty (..)) foo :: Monad m => m (NonEmpty a) -> m a foo m = do (x :| _) <- m pure x ``` It works completely fine on GHC 8.6.1 and doesn't require `MonadFail` constraint because `NonEmpty` has only single constructor so there're no other cases in pattern-matching. Howewer, if I rewrite this code using `-XPatternSynonyms` with `{-# COMPLETE #-}` pragma, it doesn't work anymore. ```hs {-# LANGUAGE PatternSynonyms #-} import Data.List.NonEmpty (NonEmpty (..)) newtype Foo a = Foo (NonEmpty a) pattern (:||) :: a -> [a] -> Foo a pattern x :|| xs <- Foo (x :| xs) {-# COMPLETE (:||) #-} foo :: Monad m => m (Foo a) -> m a foo m = do (x :|| _) <- m pure x ``` And I see the following error: ``` • Could not deduce (Control.Monad.Fail.MonadFail m) arising from a do statement with the failable pattern ‘(x :|| _)’ from the context: MonadFoo m bound by the type signature for: foo :: forall (m :: * -> *) a. MonadFoo m => m (Foo a) -> m a at /Users/fenx/haskell/sandbox/Fail.hs:13:1-37 Possible fix: add (Control.Monad.Fail.MonadFail m) to the context of the type signature for: foo :: forall (m :: * -> *) a. MonadFoo m => m (Foo a) -> m a • In a stmt of a 'do' block: (x :|| _) <- m In the expression: do (x :|| _) <- m pure x In an equation for ‘foo’: foo m = do (x :|| _) <- m pure x | 15 | (x :|| _) <- m | ^^^^^^^^^^^^^^ ``` <details><summary>Trac metadata</summary> | Trac field | Value | | ---------------------- | ------------ | | Version | 8.6.1 | | Type | Bug | | TypeOfFailure | OtherFailure | | Priority | normal | | Resolution | Unresolved | | Component | Compiler | | Test case | | | Differential revisions | | | BlockedBy | | | Related | | | Blocking | | | CC | | | Operating system | | | Architecture | | </details> <!-- {"blocked_by":[],"summary":"Take {-# COMPLETE #-} pragma into consideration when using MonadFailDesugaring","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"8.6.1","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.6.1","keywords":["pattern-matching,monadfail,desugaring"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Consider the following code:\r\n\r\n{{{#!hs\r\nimport Data.List.NonEmpty (NonEmpty (..))\r\n\r\nfoo :: Monad m => m (NonEmpty a) -> m a\r\nfoo m = do\r\n (x :| _) <- m\r\n pure x\r\n}}}\r\n\r\nIt works completely fine on GHC 8.6.1 and doesn't require `MonadFail` constraint because `NonEmpty` has only single constructor so there're no other cases in pattern-matching. Howewer, if I rewrite this code using `-XPatternSynonyms` with `{-# COMPLETE #-}` pragma, it doesn't work anymore.\r\n\r\n{{{#!hs\r\n{-# LANGUAGE PatternSynonyms #-}\r\n\r\nimport Data.List.NonEmpty (NonEmpty (..))\r\n\r\nnewtype Foo a = Foo (NonEmpty a)\r\n\r\npattern (:||) :: a -> [a] -> Foo a\r\npattern x :|| xs <- Foo (x :| xs)\r\n{-# COMPLETE (:||) #-}\r\n\r\nfoo :: Monad m => m (Foo a) -> m a\r\nfoo m = do\r\n (x :|| _) <- m\r\n pure x\r\n}}}\r\n\r\nAnd I see the following error:\r\n\r\n{{{\r\n • Could not deduce (Control.Monad.Fail.MonadFail m)\r\n arising from a do statement\r\n with the failable pattern ‘(x :|| _)’\r\n from the context: MonadFoo m\r\n bound by the type signature for:\r\n foo :: forall (m :: * -> *) a. MonadFoo m => m (Foo a) -> m a\r\n at /Users/fenx/haskell/sandbox/Fail.hs:13:1-37\r\n Possible fix:\r\n add (Control.Monad.Fail.MonadFail m) to the context of\r\n the type signature for:\r\n foo :: forall (m :: * -> *) a. MonadFoo m => m (Foo a) -> m a\r\n • In a stmt of a 'do' block: (x :|| _) <- m\r\n In the expression:\r\n do (x :|| _) <- m\r\n pure x\r\n In an equation for ‘foo’:\r\n foo m\r\n = do (x :|| _) <- m\r\n pure x\r\n |\r\n15 | (x :|| _) <- m\r\n | ^^^^^^^^^^^^^^\r\n}}}","type_of_failure":"OtherFailure","blocking":[]} -->
issue