nick8325 / quickcheck

Automatic testing of Haskell programs.
Other
713 stars 119 forks source link

Non-exhaustive pattern match warnings with `Fn`, `Fn2` and `Fn3` and `-Wincomplete-uni-patterns` #344

Closed sjakobi closed 2 years ago

sjakobi commented 2 years ago
testGroup "Fn" [
    , testProperty "test" $
      \(u :: ()) (QC.Fn f :: Fun () ()) -> f u
    , testProperty "test2" $
      \(u :: ()) (QC.Fn2 f :: Fun ((), ()) ()) -> f u u
    , testProperty "test3" $
      \(u :: ()) (QC.Fn3 f :: Fun ((), (), ()) ()) -> f u u u
    ]

Compiling this snippet results in GHC spitting out warnings:

tests/Properties/HashMapLazy.hs:484:7-46: warning: [-Wincomplete-uni-patterns]
    Pattern match(es) are non-exhaustive
    In a lambda abstraction:
        Patterns of type ‘()’, ‘Fun () ()’ not matched: () (QC.Fun _ _)
    |
484 |       \(u :: ()) (QC.Fn f :: Fun () ()) -> f u
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/Properties/HashMapLazy.hs:486:7-55: warning: [-Wincomplete-uni-patterns]
    Pattern match(es) are non-exhaustive
    In a lambda abstraction:
        Patterns of type ‘()’, ‘Fun ((), ()) ()’ not matched:
            () (QC.Fun _ _)
    |
486 |       \(u :: ()) (QC.Fn2 f :: Fun ((), ()) ()) -> f u u
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/Properties/HashMapLazy.hs:488:7-61: warning: [-Wincomplete-uni-patterns]
    Pattern match(es) are non-exhaustive
    In a lambda abstraction:
        Patterns of type ‘()’, ‘Fun ((), (), ()) ()’ not matched:
            () (QC.Fun _ _)
    |
488 |       \(u :: ()) (QC.Fn3 f :: Fun ((), (), ()) ()) -> f u u u
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is with GHC-9.2, where -Wincomplete-uni-patterns is included in -Wall. Older GHC versions don't complain unless -Wincomplete-uni-patterns is explicitly enabled.

I suspect that adding COMPLETE pragmas might silence such warnings. Does that seem like a good idea?!

Or is GHC simply misbehaving here?!

As a workaround I can use {-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-} in my relevant test modules for now.

(CC @Icelandjack who introduced these pattern synonyms in #111)

sjakobi commented 2 years ago

Ha, I should have looked at the open PRs first: https://github.com/nick8325/quickcheck/pull/336

nick8325 commented 2 years ago

Thanks for reminding me, merged the PR as you suggested!

sjakobi commented 2 years ago

Thank you for the very speedy response, @nick8325! :)