Wrong and redudant `incomplete-patterns` warnings
Summary
Recent GHC versions emit a wrong incomplete-patterns warning. Furthermore, for a similar program that deserves to be warned about, those versions are repetitive when emitting the warning. Earlier GHC versions fail to compile programs of this sort.
Steps to reproduce
A.hs
{-# language PatternSynonyms #-}
{-# options_ghc -fforce-recomp -Wall #-}
module A ( pattern P, foo ) where
pattern P :: a -> a
pattern P x = x
{-# complete P #-}
-- {-# complete P :: (,) #-} -- Needed for ghc-8.10.2 and prior.
foo :: ()
foo = case () of
P _ -> ()
B.hs
{-# language PatternSynonyms #-}
{-# options_ghc -fforce-recomp -Wall #-}
module B ( bar ) where
import A ( pattern P )
bar :: ()
bar = case ((), "") of
P ((), "hello") -> ()
C.hs
{-# language LambdaCase, PatternSynonyms #-}
{-# options_ghc -fforce-recomp -Wall #-}
module C ( woe ) where
import A ( pattern P )
woe :: () -> ()
woe = \case
P _ -> ()
Expected behavior
Do not warn
ghc-8.10.2 and ghc-9.1.0.20201115 emit the same incomplete patterns warning when compiling A.hs, the missing pattern being (). The warning might be unwarranted. On another venue, @sgraf812 said this about that:
The […] example with a
COMPLETE P :: ()on the other hand has a different quality!
Do not repeat the missing pattern
ghc-8.10.2 and ghc-9.1.0.20201115 correctly warn on B.hs about incomplete patterns but the warning carries redundant elements as shown below:
warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In a case alternative:
Patterns not matched:
((), [])
((), [])
((), [])
((), [])
...
|
| bar = case ((), "") of
| ^^^^^^^^^^^^^^^^...
Sebastian said:
[There are] duplicates the origin of which are unclear to me. I have seen that when view patterns were used, but not with just pattern synonyms. But nothing too serious.
I think it’s related to the fact that we record information about the scrutinee (e.g. that it’s
()) and then don’t store the fact that we matched onPto conclude that the match is complete. If you match on a parameterx :: ()instead, you don't get any warning.
I added C.hs to illustrate that last sentence.
Check if there is a regression test
While ghc-8.10.2 wrongly warns on C.hs, saying that the () pattern is not matched, ghc-9.1.0.20201115 does not. C.hs would then serve as a regression test, were there nothing else similar.
Explain why earlier versions can not compile these programs
ghc-8.6.5 and ghc-8.8.4 panic on any of A.hs, B.hs and C.hs.
Environment
- GHC versions used:
[8.6.5, 8.8.4, 8.10.2, head (9.1.0.20201115)]
Optional:
- Operating System: GNU/Linux
- System Architecture: x86_64
Cc @int-e @exipipiplus1 @expipiplus1