Regression in error message when attempting to let bind an existentially quantified type
When attempting to compile the following (invalid) program:
{-# LANGUAGE ExistentialQuantification #-}
data Foo = forall a. Foo a
main :: IO ()
main =
let Foo x = Foo 1 in
return ()
GHC 8.6.2.0 (and 8.6.1.0, 8.4.1.0) gives the following complicated error message
Test.hs:7:13: error:
• Couldn't match expected type ‘p’ with actual type ‘a’
because type variable ‘a’ would escape its scope
This (rigid, skolem) type variable is bound by
a pattern with constructor: Foo :: forall a. a -> Foo,
in a pattern binding
at Test.hs:7:9-13
• In the pattern: Foo x
In a pattern binding: Foo x = Foo 1
In the expression: let Foo x = Foo 1 in return ()
|
7 | let Foo x = Foo 1 in
|
GHC 7.10.1.2 gave a much more helpful and direct error message
Test.hs:7:9:
My brain just exploded
I can't handle pattern bindings for existential or GADT data constructors.
Instead, use a case-expression, or do-notation, to unpack the constructor.
In the pattern: Foo x
In a pattern binding: Foo x = Foo 1
In the expression: let Foo x = Foo 1 in return ()
Trac metadata
Trac field | Value |
---|---|
Version | 8.4.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |