Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Commit c4a876d

Browse files
xnningbgamari
authored andcommitted
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
1 parent 134de45 commit c4a876d

File tree

6 files changed

+13
-1
lines changed

6 files changed

+13
-1
lines changed

compiler/typecheck/TcHsType.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ pprSigCtxt ctxt hs_ty
174174

175175
tcHsSigWcType :: UserTypeCtxt -> LHsSigWcType GhcRn -> TcM Type
176176
-- This one is used when we have a LHsSigWcType, but in
177-
-- a place where wildards aren't allowed. The renamer has
177+
-- a place where wildcards aren't allowed. The renamer has
178178
-- already checked this, so we can simply ignore it.
179179
tcHsSigWcType ctxt sig_ty = tcHsSigType ctxt (dropWildCards sig_ty)
180180

compiler/typecheck/TcRnDriver.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {-# SOURCE #-} TcSplice ( finishTH, runRemoteModFinalizers )
5151
import RnSplice ( rnTopSpliceDecls, traceSplice, SpliceInfo(..) )
5252
import IfaceEnv( externaliseName )
5353
import TcHsType
54+
import TcValidity( checkValidType )
5455
import TcMatches
5556
import Inst( deeplyInstantiate )
5657
import TcUnify( checkConstraints )
@@ -2397,6 +2398,9 @@ tcRnType hsc_env normalise rdr_type
23972398
; kvs <- kindGeneralize kind
23982399
; ty <- zonkTcTypeToType ty
23992400

2401+
-- Do validity checking on type
2402+
; checkValidType GhciCtxt ty
2403+
24002404
; ty' <- if normalise
24012405
then do { fam_envs <- tcGetFamInstEnvs
24022406
; let (_, ty')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:set -XRankNTypes
2+
:k (Maybe Int)
3+
:k (Maybe (forall a. a -> a))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<interactive>:1:1: error:
2+
Illegal polymorphic type: forall a. a -> a
3+
GHC doesn't yet support impredicative polymorphism
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(Maybe Int) :: *

testsuite/tests/ghci/should_run/all.T

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ test('T14963a', just_ghci, ghci_script, ['T14963a.script'])
3535
test('T14963b', just_ghci, ghci_script, ['T14963b.script'])
3636
test('T14963c', [extra_hc_opts("-fdefer-type-errors")], ghci_script, ['T14963c.script'])
3737
test('T15007', just_ghci, ghci_script, ['T15007.script'])
38+
test('T15806', just_ghci, ghci_script, ['T15806.script'])

0 commit comments

Comments
 (0)