[GHC] #7857: GHC says there are unsafe overlapping instances, but only one instance applies

#7857: GHC says there are unsafe overlapping instances, but only one instance applies -----------------------------+---------------------------------------------- Reporter: dmwit | Owner: Type: bug | Status: new Priority: normal | Component: Compiler Version: 7.6.1 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- The following code rightfully does not compile: {{{ import Text.Printf f :: a -> b f = undefined g i = f $ printf "" i }}} However, the error message is a very surprising one: {{{ test.hs:6:1: Unsafe overlapping instances for PrintfType (t -> a0) arising from the ambiguity check for `g' The matching instance is: instance [safe] (PrintfArg a, PrintfType r) => PrintfType (a -> r) -- Defined in `Text.Printf' It is compiled in a Safe module and as such can only overlap instances from the same module, however it overlaps the following instances from different modules: When checking that `g' has the inferred type `forall a b t. PrintfType (t -> a) => t -> b' Probable cause: the inferred type is ambiguous }}} What I find surprising is the claim that there are overlapping instances, followed by a list of instances that clearly does not have any overlaps. For comparison, changing the definition of g to be {{{ g = f . printf "" }}} gives a much more reasonable error: {{{ test.hs:6:9: No instance for (PrintfArg a0) arising from a use of `printf' The type variable `a0' is ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there are several potential instances: instance [safe] PrintfArg Char -- Defined in `Text.Printf' instance [safe] PrintfArg Double -- Defined in `Text.Printf' instance [safe] PrintfArg Float -- Defined in `Text.Printf' ...plus 12 others In the second argument of `(.)', namely `printf ""' In the expression: f . printf "" In an equation for `g': g = f . printf "" }}} -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7857 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7857: GHC says there are unsafe overlapping instances, but only one instance applies -------------------------------+-------------------------------------------- Reporter: dmwit | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.1 Resolution: fixed | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: | Blockedby: Blocking: | Related: -------------------------------+-------------------------------------------- Changes (by simonpj): * status: new => closed * difficulty: => Unknown * resolution: => fixed Comment: Thanks. Happily, with HEAD I get {{{ T7857.hs:8:11: Could not deduce (PrintfType s0) arising from a use of ‛printf’ from the context (PrintfArg t) bound by the inferred type of g :: PrintfArg t => t -> s at T7857.hs:8:1-21 The type variable ‛s0’ is ambiguous Note: there are several potential instances: instance [safe] (PrintfArg a, PrintfType r) => PrintfType (a -> r) -- Defined in ‛Text.Printf’ instance [safe] PrintfType (IO a) -- Defined in ‛Text.Printf’ instance [safe] IsChar c => PrintfType [c] -- Defined in ‛Text.Printf’ In the second argument of ‛($)’, namely ‛printf "" i’ In the expression: f $ printf "" i In an equation for ‛g’: g i = f $ printf "" i }}} which seems very plausible. So I propose to close this as fixed; I don't think it's worth messing with the 7.6 branch. Simon -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7857#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#7857: GHC says there are unsafe overlapping instances, but only one instance applies ------------------------------------------+--------------------------------- Reporter: dmwit | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.1 Resolution: fixed | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: None/Unknown | Difficulty: Unknown Testcase: typecheck/should_fail/T7857 | Blockedby: Blocking: | Related: ------------------------------------------+--------------------------------- Changes (by simonpj): * testcase: => typecheck/should_fail/T7857 -- Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/7857#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC