Add test for #12589
[ghc.git] / testsuite / tests / typecheck / should_fail / T5051.hs
1 {-# LANGUAGE FlexibleInstances #-}
2
3 -- A very delicate interaction of overlapping instances
4
5 module T5051 where
6
7 data T = T deriving( Eq, Ord )
8 instance {-# OVERLAPPING #-} Eq [T]
9
10 foo :: Ord a => [a] -> Bool
11 foo x = x >= x
12
13 -- Bizarrely, the defn of 'foo' failed in GHC 7.0.3 with
14 -- T5051.hs:14:10:
15 -- Overlapping instances for Eq [a]
16 -- arising from a use of `>'
17 -- Matching instances:
18 -- instance Eq a => Eq [a] -- Defined in GHC.Classes
19 -- instance [overlap ok] Eq [T] -- Defined at T5051.hs:9:10-15
20 -- (The choice depends on the instantiation of `a'
21 -- To pick the first instance above, use -XIncoherentInstances
22 -- when compiling the other instance declarations)
23 -- In the expression: x > x
24 --
25 -- Reason: the dfun for Ord [a] (in the Prelude) had a "silent"
26 -- superclass parameter, thus
27 -- $dfOrdList :: forall a. (Eq [a], Ord a) => Ord [a]
28 -- Using the dfun means we need Eq [a], and that gives rise to the
29 -- overlap error.
30 --
31 -- This is terribly confusing: the use of (>=) means we need Ord [a],
32 -- and if we have Ord a (which we do) we should be done.
33 -- A very good reason for not having silent parameters!
34 -- But, alas, we need them!
35 --
36 -- Dec 14: now we don't have them any more, the test passes!