summaryrefslogtreecommitdiff
path: root/testsuite/tests/pmcheck/should_compile/EmptyCase007.hs
blob: 2d0d41668a5e58f159e6d8f5ab3ee407750325cb (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
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
{-# LANGUAGE TypeFamilies, EmptyCase, LambdaCase #-}

-- Check interaction between Newtypes and Type Families
module EmptyCase007 where

import Data.Kind (Type)

type family FA a :: Type -- just an open type family
type instance FA Int     = (Char, Bool)
type instance FA Char    = Char
type instance FA [a]     = [FA a]
type instance FA (a,b,b) = Void1

newtype Foo2 a = Foo2 (FA a)

data Void1

-- Non-exhaustive. Missing: (_ :: Foo2 a) (no info about a)
f05 :: Foo2 a -> ()
f05 = \case

-- Non-exhaustive. Missing: (_ :: Foo2 (a, a)) (does not reduce)
f06 :: Foo2 (a, a) -> ()
f06 = \case

-- Exhaustive (reduces to Void)
f07 :: Foo2 (Int, Char, Char) -> ()
f07 = \case

-- Non-exhaustive. Missing: Foo2 (_, _)
f08 :: Foo2 Int -> ()
f08 = \case

-- Non-exhaustive. Missing: Foo2 _
f09 :: Foo2 Char -> ()
f09 = \case

-- Non-exhaustive. Missing: (_ :: Char)
-- This is a more general trick: If the warning gives you a constructor form
-- and you don't know what the type of the underscore is, just match against
-- the constructor form, and the warning you'll get will fill the type in.
f09' :: Foo2 Char -> ()
f09' (Foo2 x) = case x of {}

-- Non-exhaustive. Missing: Foo2 [], Foo2 (_:_)
f10 :: Foo2 [Int] -> ()
f10 = \case