[commit: ghc] master: Fix #15954 by rejigging check_type's order (2e6cc3d)

git at git.haskell.org git at git.haskell.org
Mon Dec 3 12:47:31 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/2e6cc3d08f8439a2c0b6426e839d80072dbcda2c/ghc

>---------------------------------------------------------------

commit 2e6cc3d08f8439a2c0b6426e839d80072dbcda2c
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Mon Dec 3 07:03:52 2018 -0500

    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


>---------------------------------------------------------------

2e6cc3d08f8439a2c0b6426e839d80072dbcda2c
 compiler/typecheck/TcType.hs                       |  2 +-
 compiler/typecheck/TcValidity.hs                   | 66 ++++++++++++++++------
 compiler/types/Type.hs                             | 10 +++-
 testsuite/tests/dependent/should_fail/T15859.hs    |  1 +
 .../tests/dependent/should_fail/T15859.stderr      |  2 +-
 testsuite/tests/typecheck/should_compile/tc149.hs  |  3 +-
 testsuite/tests/typecheck/should_fail/T15954.hs    | 14 +++++
 .../tests/typecheck/should_fail/T15954.stderr      |  8 +++
 testsuite/tests/typecheck/should_fail/T7809.stderr |  6 +-
 testsuite/tests/typecheck/should_fail/all.T        |  1 +
 10 files changed, 89 insertions(+), 24 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc 2e6cc3d08f8439a2c0b6426e839d80072dbcda2c


More information about the ghc-commits mailing list