Improve error messages around kind mismatches.
authorRichard Eisenberg <rae@cs.brynmawr.edu>
Thu, 1 Jun 2017 21:27:14 +0000 (17:27 -0400)
committerRichard Eisenberg <rae@cs.brynmawr.edu>
Thu, 27 Jul 2017 11:49:05 +0000 (07:49 -0400)
commit8e15e3d370e9c253ae0dbb330e25b72cb00cdb76
tree42c5591fef14363207ab3fc86eb58d7293a1c60c
parent4a2641578bc91707e06b2f35b0fec63535e9a025
Improve error messages around kind mismatches.

Previously, when canonicalizing (or unifying, in uType) a
heterogeneous equality, we emitted a kind equality and used the
resulting coercion to cast one side of the heterogeneous equality.

While sound, this led to terrible error messages. (See the bugs
listed below.) The problem is that using the coercion built from
the emitted kind equality is a bit like a wanted rewriting a wanted.
The solution is to keep heterogeneous equalities as irreducible.

See Note [Equalities with incompatible kinds] in TcCanonical.

This commit also removes a highly suspicious switch to FM_SubstOnly
when flattening in the kinds of a type variable. I have no idea
why this was there, other than as a holdover from pre-TypeInType.
I've not left a Note because there is simply no reason I can conceive
of that the FM_SubstOnly should be there.

One challenge with this patch is that the emitted derived equalities
might get emitted several times: when a heterogeneous equality is
in an implication and then gets floated out from the implication,
the Derived is present both in and out of the implication. This
causes a duplicate error message. (Test case:
typecheck/should_fail/T7368) Solution: track the provenance of
Derived constraints and refuse to float out a constraint that has
an insoluble Derived.

Lastly, this labels one test (dependent/should_fail/RAE_T32a)
as expect_broken, because the problem is really #12919. The
different handling of constraints in this patch exposes the error.

This fixes bugs #11198, #12373, #13530, and #13610.

test cases:
typecheck/should_fail/{T8262,T8603,tcail122,T12373,T13530,T13610}
40 files changed:
compiler/typecheck/TcCanonical.hs
compiler/typecheck/TcErrors.hs
compiler/typecheck/TcEvidence.hs
compiler/typecheck/TcFlatten.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcType.hs
compiler/typecheck/TcUnify.hs
compiler/types/Type.hs
testsuite/tests/dependent/should_fail/T11471.hs
testsuite/tests/dependent/should_fail/T11471.stderr
testsuite/tests/dependent/should_fail/all.T
testsuite/tests/gadt/gadt7.stderr
testsuite/tests/ghci.debugger/scripts/break012.stdout
testsuite/tests/indexed-types/should_fail/ExtraTcsUntch.stderr
testsuite/tests/indexed-types/should_fail/T5934.stderr
testsuite/tests/polykinds/T12593.stderr
testsuite/tests/polykinds/T13555.stderr
testsuite/tests/polykinds/T7438.stderr
testsuite/tests/polykinds/T8566.stderr
testsuite/tests/polykinds/T9017.stderr
testsuite/tests/typecheck/should_fail/T12373.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T12373.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T13530.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T13530.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T13610.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T13610.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T5691.stderr
testsuite/tests/typecheck/should_fail/T7368.stderr
testsuite/tests/typecheck/should_fail/T7368a.stderr
testsuite/tests/typecheck/should_fail/T7453.stderr
testsuite/tests/typecheck/should_fail/T7696.stderr
testsuite/tests/typecheck/should_fail/T8262.stderr
testsuite/tests/typecheck/should_fail/T8603.hs
testsuite/tests/typecheck/should_fail/T8603.stderr
testsuite/tests/typecheck/should_fail/all.T
testsuite/tests/typecheck/should_fail/tcfail090.stderr
testsuite/tests/typecheck/should_fail/tcfail122.stderr
testsuite/tests/typecheck/should_fail/tcfail123.stderr
testsuite/tests/typecheck/should_fail/tcfail200.stderr