diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-03-24 18:44:08 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-03-24 18:44:28 -0400 |
commit | 5a775e62f1d8a5186e115a8ad958ad76714d3fc5 (patch) | |
tree | 59a3185a08652dd178dfe1bb009ba0a75f4d19da /rts | |
parent | 2643ba465cd2a133b6f495f34fc59cd1a6d23525 (diff) | |
download | haskell-wip/T17955.tar.gz |
Run checkNewDataCon before constraint-solving newtype constructorswip/T17955
Within `checkValidDataCon`, we used to run `checkValidType` on the
argument types of a newtype constructor before running
`checkNewDataCon`, which ensures that the user does not attempt
non-sensical things such as newtypes with multiple arguments or
constraints. This works out in most situations, but this falls over
on a corner case revealed in #17955:
```hs
newtype T = Coercible () T => T ()
```
`checkValidType`, among other things, peforms an ambiguity check on
the context of a data constructor, and that it turn invokes the
constraint solver. It turns out that there is a special case in the
constraint solver for representational equalities (read: `Coercible`
constraints) that causes newtypes to be unwrapped (see
`Note [Unwrap newtypes first]` in `TcCanonical`). This special case
does not know how to cope with an ill formed newtype like `T`, so
it ends up panicking.
The solution is surprisingly simple: just invoke `checkNewDataCon`
before `checkValidType` to ensure that the illicit newtype
constructor context is detected before the constraint solver can
run amok with it.
Fixes #17955.
Diffstat (limited to 'rts')
0 files changed, 0 insertions, 0 deletions