Fix IfaceType generation for TyCons without TyVars
authorÖmer Sinan Ağacan <omeragacan@gmail.com>
Tue, 19 Jan 2016 19:56:59 +0000 (14:56 -0500)
committerÖmer Sinan Ağacan <omeragacan@gmail.com>
Tue, 19 Jan 2016 19:57:43 +0000 (14:57 -0500)
- This is only used for printing purposes (in :browse etc.).
- Fixes #11266.

Reviewers: goldfire, bgamari, austin

Subscribers: thomie

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

GHC Trac Issues: #11266

compiler/iface/MkIface.hs
testsuite/tests/ghci/scripts/T11266.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/all.T

index 1db02bd..8548eb3 100644 (file)
@@ -1410,16 +1410,22 @@ tyConToIfaceDecl env tycon
   -- For pretty printing purposes only.
   = ( env
     , IfaceData { ifName       = getOccName tycon,
+                  ifKind       =
+                    -- These don't have `tyConTyVars`, so we use an empty
+                    -- environment here, instead of `tc_env1` defined below.
+                    tidyToIfaceType emptyTidyEnv (tyConKind tycon),
                   ifCType      = Nothing,
                   ifTyVars     = funAndPrimTyVars,
                   ifRoles      = tyConRoles tycon,
-                  ifKind       = if_kind,
                   ifCtxt       = [],
                   ifCons       = IfDataTyCon [] False [],
                   ifRec        = boolToRecFlag False,
                   ifGadtSyntax = False,
                   ifParent     = IfNoParent })
   where
+    -- NOTE: Not all TyCons have `tyConTyVars` field. Forcing this when `tycon`
+    -- is one of these TyCons (FunTyCon, PrimTyCon, PromotedDataCon) will cause
+    -- an error.
     (tc_env1, tc_tyvars) = tidyTyClTyCoVarBndrs env (tyConTyVars tycon)
     if_tc_tyvars = toIfaceTvBndrs tc_tyvars
     if_kind = tidyToIfaceType tc_env1 (tyConKind tycon)
diff --git a/testsuite/tests/ghci/scripts/T11266.script b/testsuite/tests/ghci/scripts/T11266.script
new file mode 100644 (file)
index 0000000..9b3df76
--- /dev/null
@@ -0,0 +1,2 @@
+:m + GHC.Prim
+:browse GHC.Prim
index 7a6225c..17bee5f 100755 (executable)
@@ -239,3 +239,4 @@ test('T10576a', expect_broken(10576), ghci_script, ['T10576a.script'])
 test('T10576b', expect_broken(10576), ghci_script, ['T10576b.script'])
 test('T11051a', normal, ghci_script, ['T11051a.script'])
 test('T11051b', normal, ghci_script, ['T11051b.script'])
+test('T11266', check_stdout(lambda *args: 1), ghci_script, ['T11266.script'])