[GHC] #12881: GHC 8.0.2 regression involving OVERLAP annotations

GHC ghc-devs at haskell.org
Mon Nov 28 15:21:51 UTC 2016


#12881: GHC 8.0.2 regression involving OVERLAP annotations
-------------------------------------+-------------------------------------
        Reporter:  RyanGlScott       |                Owner:
            Type:  bug               |               Status:  new
        Priority:  high              |            Milestone:  8.0.2
       Component:  Compiler          |              Version:  8.0.2-rc1
      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:                    |
-------------------------------------+-------------------------------------

@@ -16,0 +16,15 @@
+ {{{
+ $ /opt/ghc/8.0.2/bin/ghc Bug.hs
+ [1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
+
+ Bug.hs:9:10: error:
+     • Overlapping instances for Arbitrary Int
+         arising from a use of ‘Bug.$dmshrink’
+       Matching instances:
+         instance Arbitrary a -- Defined at Bug.hs:8:10
+         instance Arbitrary Int -- Defined at Bug.hs:9:10
+     • In the expression: Bug.$dmshrink @Int
+       In an equation for ‘shrink’: shrink = Bug.$dmshrink @Int
+       In the instance declaration for ‘Arbitrary Int’
+ }}}
+

New description:

 `quickcheck-combinators-0.0.1` fails to build with GHC 8.0.2-rc1 (but does
 build with GHC 8.0.1) due to this issue. Here is a simplified example:

 {{{#!hs
 {-# LANGUAGE FlexibleInstances #-}
 module Bug where

 class Arbitrary a where
   shrink :: a -> [a]
   shrink _ = []

 instance Arbitrary a
 instance Arbitrary Int
 }}}

 {{{
 $ /opt/ghc/8.0.2/bin/ghc Bug.hs
 [1 of 1] Compiling Bug              ( Bug.hs, Bug.o )

 Bug.hs:9:10: error:
     • Overlapping instances for Arbitrary Int
         arising from a use of ‘Bug.$dmshrink’
       Matching instances:
         instance Arbitrary a -- Defined at Bug.hs:8:10
         instance Arbitrary Int -- Defined at Bug.hs:9:10
     • In the expression: Bug.$dmshrink @Int
       In an equation for ‘shrink’: shrink = Bug.$dmshrink @Int
       In the instance declaration for ‘Arbitrary Int’
 }}}

 Is this expected? If so, we should make a note of this in the 8.0.2
 release notes.

--

Comment (by RyanGlScott):

 Making this even stranger, if you explicitly implement `shrink`:

 {{{#!hs
 {-# LANGUAGE FlexibleInstances #-}
 module Bug where

 class Arbitrary a where
   shrink :: a -> [a]
   shrink _ = []

 instance Arbitrary a where
   shrink _ = []

 instance Arbitrary Int where
   shrink _ = []
 }}}

 then it compiles and both versions of GHC 8.0.

 However, when you try something like this (which is basically what happens
 under the hood with default class method implementations):

 {{{#!hs
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# LANGUAGE TypeApplications #-}
 module Bug where

 class Arbitrary a where
   shrink :: a -> [a]
   shrink _ = []

 instance Arbitrary a where
   shrink = dmshrink @a

 instance Arbitrary Int where
   shrink = dmshrink @Int

 dmshrink :: Arbitrary a => a -> [a]
 dmshrink _ = []
 }}}

 Then this will fail to compile on GHC 8.0.1 //and// GHC 8.0.2.

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


More information about the ghc-tickets mailing list