Confusing type error from constrained class method
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?
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1-rc2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |