Fix two cloning-related bugs
authorSimon Peyton Jones <simonpj@microsoft.com>
Tue, 26 Jan 2016 09:30:50 +0000 (09:30 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Tue, 26 Jan 2016 09:48:20 +0000 (09:48 +0000)
commit016a0bd1ba129134dfa612db0d96e01644fa7b9f
treee68905dc574057b9639808c957952820dcd8ac95
parent1c6d70c2121fd1126fcc2458bdbcc856e19598c2
Fix two cloning-related bugs

Crikey!  Not just one but two bugs in type variable cloning,
both dating from the days before PolyKinds.  Both were shown up
by Trac #11330.

1. In SetLevels, when floating a case expression we must clone its
   binders, *and* do so in a telescope-aware way, because the
   constructor may bind a kind variable that appears in the kind
   of a type variable.

   Instead of doing this (wrongly) by steam, call CoreSubst.cloneBndrs.

   I added Notes and did other refactoring at the same time.

2. It turned out that CoreSubst.cloneBndrs calls TyCoRep.cloneTyVarBndr,
   and that too was bogus!  It didn't substitute in the kind of the
   TyVar being cloned.  There was even a comment to say "variables can't
   appear in kinds".  Thta hasn't been true for a long time now.

Easily fixed.

Interestingly, I then found that test
   dependent/should_compile/KindEqualities
was emitting a new inexhaustive-pattern-match warning.  Sure enough
it was valid!  So the lack of cloning in cloneTyVarBndr really was
causing an observable bug; just one that we had not observed.
compiler/simplCore/SetLevels.hs
compiler/types/TyCoRep.hs
testsuite/tests/dependent/should_compile/KindEqualities.stderr [new file with mode: 0644]