[GHC] #11793: Confusing type error from constrained class method

#11793: Confusing type error from constrained class method -------------------------------------+------------------------------------- Reporter: gridaphobe | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 8.0.1-rc2 Keywords: error-message | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect Unknown/Multiple | warning at compile-time Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs import GHC.Stack class Foo a where foo :: HasCallStack => a -> String instance Foo () where foo () = prettyCallStack callStack main = putStrLn (foo ()) }}} {{{ ~/S/ghc> ./inplace/bin/ghc-stage2 --make Foo.hs [1 of 1] Compiling Main ( Foo.hs, Foo.o ) Foo.hs:4:3: error: • Constraint ‘HasCallStack’ in the type of ‘foo’ constrains only the class type variables Use ConstrainedClassMethods to allow it • When checking the class method: foo :: forall a. (Foo a, HasCallStack) => a -> String In the class declaration for ‘Foo’ }}} The error says that `HasCallStack` constrains the class type variable `a`, which is incorrect. Is the error message supposed to be that `HasCallStack` '''should''' constrain the class type variable and nothing else? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11793 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11793: Confusing type error from constrained class method -------------------------------------+------------------------------------- Reporter: gridaphobe | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 8.0.1-rc2 Resolution: | Keywords: error-message Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): The original issue was this. Haskell has always allowed you to write {{{ class C a where foo :: forall b. Ord b => blah }}} (I'm using an explicit forall, which original Haskell didn't, but only to stress where the quantification is.) But Haskell 98 did not allow {{{ class C a where foo :: Ord a => blah }}} which added an extra constraint on the class variable 'a'. This was not checked by GHC 7.10, see #7854. I added the test in `f66e0e6`. But if we have implicit params should we allow {{{ class C a where foo :: ?x::Int => a -> a }}} Presumably yes. So give a constraint with free tyvars `pred_tvs`, the test should perhaps be * `pred_tvs` is not empty, and * All of the `pred_tvs` are class variables Under those circumstances, reject, unless `ConstrainedClassMethods` is on. I'll do that; it's easy. Simon GHC has no truck with such restrictions, hence the extension. But when you don't have the extension on -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11793#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11793: Confusing type error from constrained class method -------------------------------------+------------------------------------- Reporter: gridaphobe | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 8.0.1-rc2 Resolution: | Keywords: error-message Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Iceland_jack): Is this intended? {{{ $ ghci -XImplicitParams -XConstrainedClassMethods -ignore-dot-ghci GHCi, version 8.1.20160117: http://www.haskell.org/ghc/ :? for help Prelude> class C a where foo :: (?x::Int) => a -> a Prelude> class C a where foo :: ?x::Int => a -> a <interactive>:2:32: error: parse error on input ‘=>’ Prelude> }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11793#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11793: Confusing type error from constrained class method -------------------------------------+------------------------------------- Reporter: gridaphobe | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 8.0.1-rc2 Resolution: | Keywords: error-message Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj):
Is this intended?
You are asking a question about a separate thing, unrelated to this ticket, namely the parsing of implicit parameter constraints. It looks as though they have to be in parens, as things stand. So {{{ f :: (?x::Int) => blah -- ok f :: ?x::Int => blah -- not ok }}} I see no fundamental reason why the second should be not-ok. By all means open a ticket, and offer a parser patch, if you think it's important. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11793#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11793: Confusing type error from constrained class method
-------------------------------------+-------------------------------------
Reporter: gridaphobe | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 8.0.1
Component: Compiler | Version: 8.0.1-rc2
Resolution: | Keywords: error-message
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect | Unknown/Multiple
warning at compile-time | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones

#11793: Confusing type error from constrained class method -------------------------------------+------------------------------------- Reporter: gridaphobe | Owner: Type: bug | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | Version: 8.0.1-rc2 Resolution: fixed | Keywords: error-message Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed Comment: Merged to `ghc-8.0` as aab92412cf4cb77d988d36fb013018695c271ccd. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11793#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC