Skip to content

Incorrect reporting of overlapping instances

I've reproduced this issue on both 7.6.1 and 7.6.2. It does not exist on 7.4.2.

Given the following code (simplified from an actual case in Yesod):

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}

data Foo b = Foo deriving Show

class ToFoo a b where
    toFoo :: a -> Foo b

instance ToFoo (c -> ()) b where
    toFoo _ = Foo

bar :: Foo ()
bar =
    baz ()
  where
    baz () = toFoo $ \_ -> ()

main :: IO ()
main = print bar

This compiles and runs correctly with 7.4.2, producing the output "Foo". However, with 7.6.1 and 7.6.2 I get the following error message (identical between the two versions):

test.hs:16:5:
    Overlapping instances for ToFoo (t0 -> ()) b
      arising from the ambiguity check for `baz'
    Matching givens (or their superclasses):
      (ToFoo (t -> ()) b)
        bound by the inferred type for `baz':
                   ToFoo (t -> ()) b => () -> Foo b
        at test.hs:16:5-29
    Matching instances:
      instance ToFoo (c -> ()) b -- Defined at test.hs:9:10
    (The choice depends on the instantiation of `b, t0')
    When checking that `baz'
      has the inferred type `forall b t.
                             ToFoo (t -> ()) b =>
                             () -> Foo b'
    Probable cause: the inferred type is ambiguous
    In an equation for `bar':
        bar
          = baz ()
          where
              baz () = toFoo $ \ _ -> ()
Trac metadata
Trac field Value
Version 7.6.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information