Complete work on new OVERLAPPABLE/OVERLAPPING pragmas (Trac #9242)
[ghc.git] / testsuite / tests / deriving / should_compile / T4966.hs
1 {-# LANGUAGE DatatypeContexts #-}
2 {-# LANGUAGE EmptyDataDecls #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE UndecidableInstances #-}
5
6 module HTk.Toolkit.TreeList (getObjectFromTreeList) where
7
8 class Eq c => CItem c
9
10 -- A bizarre instance decl!
11 -- People who use instance decls like this are asking for trouble
12 instance {-# OVERLAPPABLE #-} GUIObject w => Eq w where
13 w1 == w2 = toGUIObject w1 == toGUIObject w2
14
15 data StateEntry a
16 = StateEntry (TreeListObject a) a -- Comment this 'a' out and it type checks
17 deriving Eq
18
19 -- The delicate point about this test is that we want to
20 -- infer a derived instance decl like this:
21 -- instance (CItem a, Eq a) => Eq (StateEntry a)
22 -- But note the instance decl for (Eq w) for any w!
23 -- There's a danger than we'll use that instance decl
24 -- to get the derived instance
25 -- instance (CItem a, GUIObject a) => Eq (StateEntry a)
26 -- And then that doesn't work subsequently
27
28 getObjectFromTreeList :: CItem a => StateEntry a -> Bool
29 getObjectFromTreeList state = state == state
30
31 data CItem a => TreeListObject a
32
33 instance {-# OVERLAPPING #-} CItem a => Eq (TreeListObject a)
34
35 class GUIObject w where
36 toGUIObject :: w -> GUIOBJECT
37
38
39 data GUIOBJECT
40
41 instance Eq GUIOBJECT where
42 (==) = undefined
43 (/=) = undefined