Fix #15954 by rejigging check_type's order
authorRyan Scott <ryan.gl.scott@gmail.com>
Mon, 3 Dec 2018 12:03:52 +0000 (07:03 -0500)
committerRyan Scott <ryan.gl.scott@gmail.com>
Mon, 3 Dec 2018 12:03:52 +0000 (07:03 -0500)
commit2e6cc3d08f8439a2c0b6426e839d80072dbcda2c
tree55116f80290bc8e12e68d917265ae03003775921
parent75a8349b2a7d0142d3d687837caf5a95bbb4368d
Fix #15954 by rejigging check_type's order

Summary:
Previously, `check_type` (which catches illegal uses of
unsaturated type synonyms without enabling `LiberalTypeSynonyms`,
among other things) always checks for uses of polytypes before
anything else. There is a problem with this plan, however:
checking for polytypes requires decomposing `forall`s and other
invisible arguments, an action which itself expands type synonyms!
Therefore, if we have something like:

```lang=haskell
type A a = Int
type B (a :: Type -> Type) = forall x. x -> x
type C = B A
```

Then when checking `B A`, `A` will get expanded to `forall x. x -> x`
before `check_type` has an opportunity to realize that `A` is an
unsaturated type synonym! This is the root cause of #15954.

This patch fixes the issue by moving the case of `check_type` that
detects polytypes to be //after// the case that checks for
`TyConApp`s. That way, the `TyConApp` case will properly flag things
like the unsaturated use of `A` in the example above before we ever
attempt to check for polytypes.

Test Plan: make test TEST=T15954

Reviewers: simonpj, bgamari, goldfire

Reviewed By: simonpj

Subscribers: rwbarton, carter

GHC Trac Issues: #15954

Differential Revision: https://phabricator.haskell.org/D5402
compiler/typecheck/TcType.hs
compiler/typecheck/TcValidity.hs
compiler/types/Type.hs
testsuite/tests/dependent/should_fail/T15859.hs
testsuite/tests/dependent/should_fail/T15859.stderr
testsuite/tests/typecheck/should_compile/tc149.hs
testsuite/tests/typecheck/should_fail/T15954.hs [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T15954.stderr [new file with mode: 0644]
testsuite/tests/typecheck/should_fail/T7809.stderr
testsuite/tests/typecheck/should_fail/all.T