Wrong instance selection with overlapping instance in a superclass
test_foo and test_bar should have the same type, but it seems like the non-{#- OVERLAPPING #-} instance is chosen prematurely.
{-# LANGUAGE NoMonomorphismRestriction, FlexibleContexts, FlexibleInstances #-}
module Bug where
class A a where
class A a => B a where
data Foo s a
instance {-# OVERLAPPING #-} A (Foo Int Bool)
instance A (Foo s a)
instance B (Foo s a)
helper :: Foo s Bool -> s -> Int
helper = undefined
foo :: (A a, B a) => a
foo = undefined
bar :: B a => a
bar = undefined
{-
*Bug> :t test_foo
test_foo :: A (Foo s Bool) => s -> Int
-}
test_foo = helper foo
{-
*Bug> :t test_bar
test_bar :: s -> Int
-}
test_bar = helper bar
Compare with 7.10.3:
*Bug> :t test_foo
test_foo :: A (Foo s Bool) => s -> Int
*Bug> :t test_bar
test_bar :: A (Foo s Bool) => s -> Int