summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZubin Duggal <zubin.duggal@gmail.com>2021-05-28 18:43:59 +0530
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-06-02 04:39:58 -0400
commitadddf2484b2bef05ea8d7b17b926e874d9d2e833 (patch)
treeb82e5529ddfc7e3bc5cda6b437fba46ceea85d59
parentfcd124d5c7c1c4ea8488587f65112b7a66b7da83 (diff)
downloadhaskell-adddf2484b2bef05ea8d7b17b926e874d9d2e833.tar.gz
Fail before checking instances in checkHsigIface if exports don't match (#19244)
-rw-r--r--compiler/GHC/Tc/Utils/Backpack.hs9
-rw-r--r--testsuite/tests/backpack/should_compile/all.T2
-rw-r--r--testsuite/tests/backpack/should_fail/T19244a.bkp (renamed from testsuite/tests/backpack/should_compile/T19244a.bkp)0
-rw-r--r--testsuite/tests/backpack/should_fail/T19244a.stderr71
-rw-r--r--testsuite/tests/backpack/should_fail/T19244b.bkp (renamed from testsuite/tests/backpack/should_compile/T19244b.bkp)0
-rw-r--r--testsuite/tests/backpack/should_fail/T19244b.stderr21
-rw-r--r--testsuite/tests/backpack/should_fail/all.T2
7 files changed, 103 insertions, 2 deletions
diff --git a/compiler/GHC/Tc/Utils/Backpack.hs b/compiler/GHC/Tc/Utils/Backpack.hs
index 837ab3d2a7..4af4aae1e1 100644
--- a/compiler/GHC/Tc/Utils/Backpack.hs
+++ b/compiler/GHC/Tc/Utils/Backpack.hs
@@ -132,6 +132,7 @@ checkHsigIface tcg_env gr sig_iface
traceTc "checkHsigIface" $ vcat
[ ppr sig_type_env, ppr sig_insts, ppr sig_exports ]
mapM_ check_export (map availName sig_exports)
+ failIfErrsM -- See Note [Fail before checking instances in checkHsigIface]
unless (null sig_fam_insts) $
panic ("GHC.Tc.Module.checkHsigIface: Cannot handle family " ++
"instances in hsig files yet...")
@@ -192,6 +193,14 @@ checkHsigIface tcg_env gr sig_iface
addErrAt (nameSrcSpan name)
(missingBootThing False name "exported by")
+-- Note [Fail before checking instances in checkHsigIface]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-- We need to be careful about failing before checking instances if there happens
+-- to be an error in the exports.
+-- Otherwise, we might proceed with typechecking (and subsequently panic-ing) on
+-- ill-kinded types that are constructed while checking instances.
+-- This lead to #19244
+
-- Note [Error reporting bad reexport]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- NB: You want to be a bit careful about what location you report on reexports.
diff --git a/testsuite/tests/backpack/should_compile/all.T b/testsuite/tests/backpack/should_compile/all.T
index a747a461a4..ac8c2a7ed8 100644
--- a/testsuite/tests/backpack/should_compile/all.T
+++ b/testsuite/tests/backpack/should_compile/all.T
@@ -58,5 +58,3 @@ test('T13149', expect_broken(13149), backpack_compile, [''])
test('T13214', normal, backpack_compile, [''])
test('T13250', normal, backpack_compile, [''])
test('T13323', normal, backpack_compile, [''])
-test('T19244a', expect_broken(19244), backpack_compile, [''])
-test('T19244b', expect_broken(19244), backpack_compile, [''])
diff --git a/testsuite/tests/backpack/should_compile/T19244a.bkp b/testsuite/tests/backpack/should_fail/T19244a.bkp
index 6897378240..6897378240 100644
--- a/testsuite/tests/backpack/should_compile/T19244a.bkp
+++ b/testsuite/tests/backpack/should_fail/T19244a.bkp
diff --git a/testsuite/tests/backpack/should_fail/T19244a.stderr b/testsuite/tests/backpack/should_fail/T19244a.stderr
new file mode 100644
index 0000000000..76f0c86661
--- /dev/null
+++ b/testsuite/tests/backpack/should_fail/T19244a.stderr
@@ -0,0 +1,71 @@
+[1 of 4] Processing user
+ [1 of 2] Compiling Map[sig] ( user/Map.hsig, nothing )
+ [2 of 2] Compiling User ( user/User.hs, nothing )
+[2 of 4] Processing ordmap
+ Instantiating ordmap
+ [1 of 1] Compiling Map ( ordmap/Map.hs, T19244a.out/ordmap/Map.o )
+[3 of 4] Processing eqmap
+ Instantiating eqmap
+ [1 of 1] Compiling Map ( eqmap/Map.hs, T19244a.out/eqmap/Map.o )
+[4 of 4] Processing main
+ Instantiating main
+ [1 of 2] Including user[Map=ordmap:Map]
+ Instantiating user[Map=ordmap:Map]
+ [1 of 2] Compiling Map[sig] ( user/Map.hsig, T19244a.out/user/user-GzloW2NeDdA2M0V8qzN4g2/Map.o )
+
+T19244a.bkp:9:9: error:
+ • Type constructor ‘Map’ has conflicting definitions in the module
+ and its hsig file
+ Main module: type role Map nominal representational
+ type Map :: * -> * -> *
+ data Map k a
+ = Data.Map.Internal.Bin {-# UNPACK #-}Data.Map.Internal.Size
+ !k
+ a
+ !(Map k a)
+ !(Map k a)
+ | Data.Map.Internal.Tip
+ Hsig file: type role Map nominal representational
+ type Map :: forall {k} {k1}. k -> k1 -> *
+ data Map k2 a
+ The types have different kinds
+ • while checking that ordmap:Map implements signature Map in user[Map=ordmap:Map]
+
+T19244a.bkp:22:9: error:
+ • Type constructor ‘Key’ has conflicting definitions in the module
+ and its hsig file
+ Main module: type Key :: * -> Constraint
+ type Key = GHC.Classes.Ord :: * -> Constraint
+ Hsig file: type Key :: forall {k}. k -> Constraint
+ class Key k1
+ The types have different kinds
+ • while checking that ordmap:Map implements signature Map in user[Map=ordmap:Map]
+
+<no location info>: error:
+ • Identifier ‘lookup’ has conflicting definitions in the module
+ and its hsig file
+ Main module: lookup ::
+ GHC.Classes.Ord k => k -> Map k a -> GHC.Maybe.Maybe a
+ Hsig file: lookup ::
+ Key (*) k => k -> Map (*) (*) k a -> GHC.Maybe.Maybe a
+ The two types are different
+ • while checking that ordmap:Map implements signature Map in user[Map=ordmap:Map]
+
+<no location info>: error:
+ • Identifier ‘insert’ has conflicting definitions in the module
+ and its hsig file
+ Main module: insert ::
+ GHC.Classes.Ord k => k -> a -> Map k a -> Map k a
+ Hsig file: insert ::
+ Key (*) k => k -> a -> Map (*) (*) k a -> Map (*) (*) k a
+ The two types are different
+ • while checking that ordmap:Map implements signature Map in user[Map=ordmap:Map]
+
+<no location info>: error:
+ • Identifier ‘empty’ has conflicting definitions in the module
+ and its hsig file
+ Main module: empty :: Map k a
+ Hsig file: empty ::
+ forall {k1} {k2} (k3 :: k1) (a :: k2). Map k1 k2 k3 a
+ The two types are different
+ • while checking that ordmap:Map implements signature Map in user[Map=ordmap:Map]
diff --git a/testsuite/tests/backpack/should_compile/T19244b.bkp b/testsuite/tests/backpack/should_fail/T19244b.bkp
index 152a7d6449..152a7d6449 100644
--- a/testsuite/tests/backpack/should_compile/T19244b.bkp
+++ b/testsuite/tests/backpack/should_fail/T19244b.bkp
diff --git a/testsuite/tests/backpack/should_fail/T19244b.stderr b/testsuite/tests/backpack/should_fail/T19244b.stderr
new file mode 100644
index 0000000000..3a50d11079
--- /dev/null
+++ b/testsuite/tests/backpack/should_fail/T19244b.stderr
@@ -0,0 +1,21 @@
+[1 of 3] Processing user
+ [1 of 2] Compiling Map[sig] ( user/Map.hsig, nothing )
+ [2 of 2] Compiling User ( user/User.hs, nothing )
+[2 of 3] Processing ordmap
+ Instantiating ordmap
+ [1 of 1] Compiling Map ( ordmap/Map.hs, T19244b.out/ordmap/Map.o )
+[3 of 3] Processing main
+ Instantiating main
+ [1 of 1] Including user[Map=ordmap:Map]
+ Instantiating user[Map=ordmap:Map]
+ [1 of 2] Compiling Map[sig] ( user/Map.hsig, T19244b.out/user/user-GzloW2NeDdA2M0V8qzN4g2/Map.o )
+
+T19244b.bkp:11:27: error:
+ • Type constructor ‘Key’ has conflicting definitions in the module
+ and its hsig file
+ Main module: type Key :: * -> Constraint
+ type Key = GHC.Classes.Ord :: * -> Constraint
+ Hsig file: type Key :: forall {k}. k -> Constraint
+ class Key k1
+ The types have different kinds
+ • while checking that ordmap:Map implements signature Map in user[Map=ordmap:Map]
diff --git a/testsuite/tests/backpack/should_fail/all.T b/testsuite/tests/backpack/should_fail/all.T
index 5e0d6fdeea..e01a4281a5 100644
--- a/testsuite/tests/backpack/should_fail/all.T
+++ b/testsuite/tests/backpack/should_fail/all.T
@@ -49,3 +49,5 @@ test('bkpfail50', normal, backpack_compile_fail, [''])
test('bkpfail51', normal, backpack_compile_fail, [''])
test('bkpfail52', normal, backpack_compile_fail, [''])
test('bkpfail53', normal, backpack_compile_fail, [''])
+test('T19244a', normal, backpack_compile_fail, [''])
+test('T19244b', normal, backpack_compile_fail, [''])