• Ryan Scott's avatar
    Fix #15954 by rejigging check_type's order · 2e6cc3d0
    Ryan Scott authored
    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:
    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
all.T 21.9 KB