Opened 3 years ago

Closed 3 years ago

#7641 closed bug (fixed)

Incorrect reporting of overlapping instances

Reported by: snoyberg Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


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 ()
    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):

    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':
          = baz ()
              baz () = toFoo $ \ _ -> ()

Change History (1)

comment:1 Changed 3 years ago by goldfire

  • Resolution set to fixed
  • Status changed from new to closed

This is fixed in HEAD -- I was able to compile the code without a hiccup.

Thanks for the report!

Note: See TracTickets for help on using tickets.