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