Commit 718a0181 authored by Ryan Scott's avatar Ryan Scott

Fix #14238 by always pretty-printing visible tyvars

Summary:
Before, GHC would never print visible tyvars in the absence
of `-fprint-explicit-foralls`, which led to `:kind` displaying
incorrect kinds in GHCi. The fix is simple—simply check beforehand
if any of the type variable binders are required when deciding when
to pretty-print them.

Test Plan: make test TEST=T14238

Reviewers: simonpj, goldfire, bgamari

Subscribers: thomie, carter

GHC Trac Issues: #14238

Differential Revision: https://phabricator.haskell.org/D4564
parent 875e59d3
......@@ -860,11 +860,46 @@ pprIfaceSigmaType show_forall ty
pprUserIfaceForAll :: [IfaceForAllBndr] -> SDoc
pprUserIfaceForAll tvs
= sdocWithDynFlags $ \dflags ->
ppWhen (any tv_has_kind_var tvs || gopt Opt_PrintExplicitForalls dflags) $
-- See Note [When to print foralls]
ppWhen (any tv_has_kind_var tvs
|| any tv_is_required tvs
|| gopt Opt_PrintExplicitForalls dflags) $
pprIfaceForAll tvs
where
tv_has_kind_var (TvBndr (_,kind) _) = not (ifTypeIsVarFree kind)
tv_is_required = isVisibleArgFlag . binderArgFlag
{-
Note [When to print foralls]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We opt to explicitly pretty-print `forall`s if any of the following
criteria are met:
1. -fprint-explicit-foralls is on.
2. A bound type variable has a polymorphic kind. E.g.,
forall k (a::k). Proxy a -> Proxy a
Since a's kind mentions a variable k, we print the foralls.
3. A bound type variable is a visible argument (#14238).
Suppose we are printing the kind of:
T :: forall k -> k -> Type
The "forall k ->" notation means that this kind argument is required.
That is, it must be supplied at uses of T. E.g.,
f :: T (Type->Type) Monad -> Int
So we print an explicit "T :: forall k -> k -> Type",
because omitting it and printing "T :: k -> Type" would be
utterly misleading.
See Note [TyVarBndrs, TyVarBinders, TyConBinders, and visibility]
in TyCoRep.
-}
-------------------
......
:set -XTypeInType
:m + Data.Kind
data Foo (k :: Type) :: k -> Type
:kind Foo
......@@ -2,3 +2,4 @@ test('T11549',
[ expect_broken( 11787 ),
expect_broken( 11786 ) ],
ghci_script, ['T11549.script'])
test('T14238', normal, ghci_script, ['T14238.script'])
Proxy1 :: k -> *
Proxy1 :: forall k -> k -> *
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment