
#12201: Wrong instance selection with overlapping instance in a superclass -------------------------------------+------------------------------------- Reporter: kanetw | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler (Type | Version: 8.0.1 checker) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by kanetw: @@ -1,2 +1,2 @@ - test and test2 should have the same type, but it seems like the non-{#- - OVERLAPPING #-} instance is chosen prematurely. + test_foo and test_bar should have the same type, but it seems like the + non-{#- OVERLAPPING #-} instance is chosen prematurely. @@ -16,3 +16,0 @@ - bar :: (A a, B a) => a - bar = undefined - @@ -22,5 +19,5 @@ - {- - *Bug> :t test - test :: A (Foo s Bool) => s -> Int - -} - test = helper bar + foo :: (A a, B a) => a + foo = undefined + + bar :: B a => a + bar = undefined @@ -29,2 +26,2 @@ - *Bug> :t test2 - test2 :: s -> Int + *Bug> :t test_foo + test_foo :: A (Foo s Bool) => s -> Int @@ -32,1 +29,7 @@ - test2 = let foo = bar in helper foo + test_foo = helper foo + + {- + *Bug> :t test_bar + test_bar :: s -> Int + -} + test_bar = helper bar @@ -37,4 +40,4 @@ - *Bug> :t test - test :: A (Foo s Bool) => s -> Int - *Bug> :t test2 - test2 :: A (Foo s Bool) => s -> Int + *Bug> :t test_foo + test_foo :: A (Foo s Bool) => s -> Int + *Bug> :t test_bar + test_bar :: A (Foo s Bool) => s -> Int New description: test_foo and test_bar should have the same type, but it seems like the non-{#- OVERLAPPING #-} instance is chosen prematurely. {{{#!hs {-# 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 }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12201#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler