Tidying could cause ill-kinded types
authorSimon Peyton Jones <simonpj@microsoft.com>
Sat, 2 Sep 2017 17:29:11 +0000 (18:29 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Thu, 14 Sep 2017 07:37:24 +0000 (08:37 +0100)
commit8bf865d3db69c6f4a09f3e5e3880c087c0a7c7f0
treec071652d8af1ba5f2a7aa789a45addc8c96976d9
parent3a27e34f7a59a30f91fad9dd2ca194acdb1bcb1a
Tidying could cause ill-kinded types

I found (Trac #14175) that the tidying we do when reporting
type error messages could cause a well-kinded type to become
ill-kinded. Reason: we initialised the tidy-env with a
completely un-zonked TidyEnv accumulated in the TcLclEnv
as we come across lexical type-varialbe bindings.

Solution: zonk them.

But I ended up refactoring a bit:

* Get rid of tcl_tidy :: TidyEnv altogether

* Instead use tcl_bndrs :: TcBinderStack
  This used to contain only Ids, but now I've added those
  lexically scoped TyVars too.

* Change names:
     TcIdBinderStack -> TcBinderStack
     TcIdBinder      -> TcBinder
     extendTcIdBndrs -> extendTcBinderStack

* Now tcInitTidyEnv can grab those TyVars from the
  tcl_bndrs, zonk, and tidy them.

The only annoyance is that I had to add TcEnv.hs-boot, to
break the recursion between the zonking code and the
TrRnMonad functions like addErrTc that call tcInitTidyEnv.
Tiresome, but in fact that file existed already.
compiler/typecheck/TcBinds.hs
compiler/typecheck/TcEnv.hs
compiler/typecheck/TcEnv.hs-boot
compiler/typecheck/TcErrors.hs
compiler/typecheck/TcRnMonad.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcValidity.hs
testsuite/tests/indexed-types/should_fail/T14175.hs [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/T14175.stderr [new file with mode: 0644]
testsuite/tests/indexed-types/should_fail/all.T