Commit 2cc42dbb authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

When printing types in the interactive UI, take account of free variables

Often the types we print are full-generalised, but in fact *kinds* are
not, so we need to use tidyOpenType.

Fixes Trac #7587
parent 2ec39c76
......@@ -1614,6 +1614,7 @@ hscImport hsc_env str = runInteractiveHsc hsc_env $ do
ptext (sLit "parse error in import declaration")
-- | Typecheck an expression (but don't run it)
-- Returns its most general type
hscTcExpr :: HscEnv
-> String -- ^ The expression
-> IO Type
......@@ -1628,6 +1629,7 @@ hscTcExpr hsc_env0 expr = runInteractiveHsc hsc_env0 $ do
(text "not an expression:" <+> quotes (text expr))
-- | Find the kind of a type
-- Currently this does *not* generalise the kinds of the type
hscKcType
:: HscEnv
-> Bool -- ^ Normalise the type
......
......@@ -972,6 +972,7 @@ parseName str = withSession $ \hsc_env -> do
-- Getting the type of an expression
-- | Get the type of an expression
-- Returns its most general type
exprType :: GhcMonad m => String -> m Type
exprType expr = withSession $ \hsc_env -> do
ty <- liftIO $ hscTcExpr hsc_env expr
......
......@@ -33,6 +33,7 @@ import Coercion( pprCoAxiom )
import HscTypes( tyThingParent_maybe )
import TcType
import Name
import VarEnv( emptyTidyEnv )
import StaticFlags( opt_PprStyle_Debug )
import Outputable
import FastString
......@@ -161,8 +162,12 @@ pprTypeForUser print_foralls ty
| print_foralls = ppr tidy_ty
| otherwise = ppr (mkPhiTy ctxt ty')
where
tidy_ty = tidyTopType ty
(_, ctxt, ty') = tcSplitSigmaTy tidy_ty
(_, tidy_ty) = tidyOpenType emptyTidyEnv ty
-- Often the types/kinds we print in ghci are fully generalised
-- and have no free variables, but it turns out that we sometimes
-- print un-generalised kinds (eg when doing :k T), so it's
-- better to use tidyOpenType here
pprTyCon :: PrintExplicitForalls -> ShowSub -> TyCon -> SDoc
pprTyCon pefas ss tyCon
......
......@@ -1529,6 +1529,7 @@ tcRnExpr :: HscEnv
-> InteractiveContext
-> LHsExpr RdrName
-> IO (Messages, Maybe Type)
-- Type checks the expression and returns its most general type
tcRnExpr hsc_env ictxt rdr_expr
= initTcPrintErrors hsc_env iNTERACTIVE $
setInteractiveContext hsc_env ictxt $ do {
......
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