summaryrefslogtreecommitdiff
path: root/testsuite/tests/patsyn/should_fail/T11667.hs
blob: f2437fa8c5940284dbb72efcb0b8f95bab8bfd6f (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
{-# LANGUAGE PatternSynonyms, GADTs #-}
module T11667 where

{-
The following four pattern synonym declarations should give valid
error messages
-}

-- Check if we mention no explicit type signature (or the correct
-- signature "Eq a => Maybe a")
pattern Pat1 :: Eq a => Maybe a
pattern Pat1 <- Just 42

-- Check if we mention no explicit type signature (or the correct
-- signature "forall b. () => forall a. b ~ Bool => a -> b -> (b, T)")
data T where MkT :: a -> T
pattern Pat2 :: () => b ~ Bool => a -> b -> (b, T)
pattern Pat2 x y = (y, MkT x)

-- Check if we do not tell the user that we could not deduce (Show a)
-- from the "required" context. Also, check if we do not give the
-- possible fix that suggests to add (Show a) to the "required" context.
pattern Pat3 :: Eq a => Show a => a -> Maybe a
pattern Pat3 x <- Just x

-- Check if we return a valid error message concerning the missing
-- constraint (Num a) when the bidirectional pattern synonym is used
-- in an expression context
data S a where MkS :: (Num a, Show a) => a -> S a
pattern Pat4 :: (Eq a) => (Show a) => S a
pattern Pat4 = MkS 42