Bump `base` version to 4.9.0.0 (closes #11026)
[ghc.git] / testsuite / tests / typecheck / should_fail / T5684.hs
1 {-# OPTIONS -XFunctionalDependencies -XUndecidableInstances -XFlexibleInstances #-}
2
3 module T5684 where
4
5 class B a b | a -> b where
6 op :: a -> b -> ()
7
8 class A a | -> a
9
10 instance A b => B Bool b
11
12 {- This used to be a bug in various versions of GHC <= 7.2.2
13 The source of the problem is the kicking out of inert Solved goals back to
14 the worklist, which violated our invariant that when two constraints of the
15 same class meet (workitem-inert) then the combination (Given-Wanted) is impossible.
16 Actually it turns our that it is possible. The order in which the constraints appear
17 below is important so we add two combinations to make sure that the testcase is
18 order-insensitive. -}
19
20 flop1 = [ op False False -- (3) Creates a functional dependency which kicks the solved out
21 -- back in the worklist. Next time round the solved workitem
22 -- meets the wanted from stage (2) and boom, the assertion fails!
23
24 , op 'c' undefined -- (2) Creates a ([W] B Char beta) permanently in inerts
25 , op True undefined -- (1) Creates ([W] B Bool alpha)
26 -- which immediately becomes [S] B Bool alpha
27 ]
28
29 flop2 = [ op False False
30 , op True undefined
31 , op 'c' undefined
32 ]
33
34
35 flop3 = [ op 'c' undefined
36 , op True undefined
37 , op False False
38 ]
39
40 flop4 = [ op 'c' undefined
41 , op False False
42 , op True undefined
43 ]
44
45
46 flop5 = [ op True undefined
47 , op 'c' undefined
48 , op False False
49 ]
50
51
52 flop6 = [ op True undefined
53 , op False False
54 , op 'c' undefined
55 ]
56
57
58 {- Now, in HEAD we no longer have cached GivenSolved goals in the inerts and hence
59 this situation can no longer appear. If a Given gets kicked out it is only because
60 it got rewritten by a given equality: Notice that since Givens now never contain
61 plain old unification variables (since they are not GivenSolveds!) they can never be
62 rewritten by a spontaneously solved either! So our invariant now holds. -}