Improve error message for type rigidity
When saying that a GADT match is given a non-rigid type, we should be more explicit about where a type signature would help. For example, given the program:
data E x = E x
data Foo a where
Foo :: Gadt a -> Foo a
data Gadt a where
GadtValue :: a -> Gadt (E a)
g = case undefined of
Foo GadtValue -> ()
I get the error message:
Test.hs:13:12:
GADT pattern match with non-rigid result type `t'
Solution: add a type signature
In a case alternative: Foo GadtValue -> ()
In the expression: case undefined of { Foo GadtValue -> () }
In the definition of `g':
g = case undefined of { Foo GadtValue -> () }
But where should the type signature be? A better hint would be:
Solution: add a type signature, probably at _TYPE_
(case undefined of { Foo GadtValue -> () }) :: _TYPE_
Similarly, we know when it's the scrutinee that needs a signature. And in a do-binding the "scrutinee" is really the right-hand side. We can get all this information from the matching context.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 6.8.3 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | Unknown |
| Architecture | Unknown |