[GHC] #12201: Wrong instance selection with overlapping instances and local bindings

GHC ghc-devs at haskell.org
Fri Jun 17 16:04:30 UTC 2016


#12201: Wrong instance selection with overlapping instances and local bindings
-------------------------------------+-------------------------------------
        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:                    |
-------------------------------------+-------------------------------------

Comment (by kanetw):

 GHC doesn't seem to check superclass constraints for overlap before
 solving.

 {{{#!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
 }}}

 GHC7 works as expected. I suspect the recent superclass solver changes
 caused this.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12201#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list