Commit 804518f7 authored by Ningning Xie's avatar Ningning Xie Committed by Ben Gamari

Fix `:k` command: add validity checking

Summary:
This patch fixes #15806, where we found that the `:k` command in GHCi
misses a validity checking for the type.

Missing validity checking causes `:k` to accept types that are not validated.
For example, `:k (Maybe (forall a. a -> a))` (incorrectly) returns `*`, while
impredictivity of type instantiation shouldn't be allowed.

Test Plan: ./validate

Reviewers: simonpj, goldfire, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, carter

GHC Trac Issues: #15806

Differential Revision: https://phabricator.haskell.org/D5265

(cherry picked from commit 12cb5cf50b8b35394e2e2d57e1ac693c76f90833)
parent b539a99c
......@@ -171,7 +171,7 @@ pprSigCtxt ctxt hs_ty
tcHsSigWcType :: UserTypeCtxt -> LHsSigWcType GhcRn -> TcM Type
-- This one is used when we have a LHsSigWcType, but in
-- a place where wildcards aren't allowed. The renamer has
-- already checked this, so we can simply ignore it.
tcHsSigWcType ctxt sig_ty = tcHsSigType ctxt (dropWildCards sig_ty)
......
......@@ -51,6 +51,7 @@ import {-# SOURCE #-} TcSplice ( finishTH )
import RnSplice ( rnTopSpliceDecls, traceSplice, SpliceInfo(..) )
import IfaceEnv( externaliseName )
import TcHsType
import TcValidity( checkValidType )
import TcMatches
import Inst( deeplyInstantiate )
import TcUnify( checkConstraints )
......@@ -2375,6 +2376,9 @@ tcRnType hsc_env normalise rdr_type
; kvs <- kindGeneralize kind
; ty <- zonkTcTypeToType emptyZonkEnv ty
-- Do validity checking on type
; checkValidType GhciCtxt ty
; ty' <- if normalise
then do { fam_envs <- tcGetFamInstEnvs
; let (_, ty')
......
:set -XRankNTypes
:k (Maybe Int)
:k (Maybe (forall a. a -> a))
\ No newline at end of file
<interactive>:1:1: error:
Illegal polymorphic type: forall a. a -> a
GHC doesn't yet support impredicative polymorphism
\ No newline at end of file
(Maybe Int) :: *
\ No newline at end of file
......@@ -33,3 +33,4 @@ test('T13825-ghci',just_ghci, ghci_script, ['T13825-ghci.script'])
test('T14963a', just_ghci, ghci_script, ['T14963a.script'])
test('T14963b', just_ghci, ghci_script, ['T14963b.script'])
test('T14963c', [extra_hc_opts("-fdefer-type-errors")], ghci_script, ['T14963c.script'])
test('T15806', just_ghci, ghci_script, ['T15806.script'])
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