summaryrefslogtreecommitdiff
path: root/testsuite/tests/pmcheck/should_compile/EmptyCase002.hs
blob: 416913a6ea4d720fc14fbde68211f7870f04c241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{-# OPTIONS_GHC -fwarn-incomplete-patterns  #-}
{-# LANGUAGE EmptyCase, LambdaCase          #-}
{-# LANGUAGE GADTs, TypeFamilies            #-}

-- Check some newtypes, in combination with GADTs and TypeFamilies
module EmptyCase002 where

import Data.Kind (Type)

newtype T = MkT H
newtype G = MkG T
newtype H = MkH G

-- Exhaustive but it cannot be detected.
f1 :: T -> a
f1 = \case

data A

data B = B1 | B2

data C :: Type -> Type where
  C1 :: C Int
  C2 :: C Bool

data D :: Type -> Type -> Type where
  D1 :: D Int  Bool
  D2 :: D Bool Char

type family E (a :: Type) :: Type where
  E Int  = Bool
  E Bool = Char

newtype T1 a = MkT1 a
newtype T2 b = MkT2 b

-- Exhaustive
f2 :: T1 A -> z
f2 = \case

-- Non-exhaustive. Missing cases: MkT1 B1, MkT1 B2
f3 :: T1 B -> z
f3 = \case

-- Non-exhaustive. Missing cases: MkT1 False, MkT1 True
f4 :: T1 (E Int) -> z
f4 = \case

-- Non-exhaustive. Missing cases: MkT1 (MkT2 (MkT1 D2))
f5 :: T1 (T2 (T1 (D (E Int) (E (E Int))))) -> z
f5 = \case

-- Exhaustive. Not an EmptyCase but good to have for
-- comparison with the example above
f6 :: T1 (T2 (T1 (D (E Int) (E (E Int))))) -> ()
f6 = \case MkT1 (MkT2 (MkT1 D2)) -> ()