summaryrefslogtreecommitdiff
path: root/compiler/hsSyn
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2011-01-10 11:03:51 +0000
committersimonpj@microsoft.com <unknown>2011-01-10 11:03:51 +0000
commit6ea06bbf08517d9805feb82df65cc56ecbaf23a4 (patch)
tree0f7d4d11bda62cbe37f3f5842e233e369071c691 /compiler/hsSyn
parent338cac018258e0c5540e18e0efe7dc84dfce8c86 (diff)
downloadhaskell-6ea06bbf08517d9805feb82df65cc56ecbaf23a4.tar.gz
Do dependency analysis when kind-checking type declarations
This patch fixes Trac #4875. The main point is to do dependency analysis on type and class declarations, and kind-check them in dependency order, so as to improve error messages. This patch means that a few programs that would typecheck before won't typecheck any more; but before we were (naughtily) going beyond Haskell 98 without any language-extension flags, and Trac #4875 convinces me that doing so is a Bad Idea. Here's an example that won't typecheck any more data T a b = MkT (a b) type F k = T k Maybe If you look at T on its own you'd default 'a' to kind *->*; and then kind-checking would fail on F. But GHC currently accepts this program beause it looks at the *occurrences* of T.
Diffstat (limited to 'compiler/hsSyn')
-rw-r--r--compiler/hsSyn/HsDecls.lhs10
-rw-r--r--compiler/hsSyn/HsUtils.lhs7
2 files changed, 12 insertions, 5 deletions
diff --git a/compiler/hsSyn/HsDecls.lhs b/compiler/hsSyn/HsDecls.lhs
index fd6d3bbf45..8827f3ab64 100644
--- a/compiler/hsSyn/HsDecls.lhs
+++ b/compiler/hsSyn/HsDecls.lhs
@@ -126,7 +126,12 @@ data HsDecl id
data HsGroup id
= HsGroup {
hs_valds :: HsValBinds id,
- hs_tyclds :: [LTyClDecl id],
+
+ hs_tyclds :: [[LTyClDecl id]],
+ -- A list of mutually-recursive groups
+ -- Parser generates a singleton list;
+ -- renamer does dependency analysis
+
hs_instds :: [LInstDecl id],
hs_derivds :: [LDerivDecl id],
@@ -228,7 +233,8 @@ instance OutputableBndr name => Outputable (HsGroup name) where
if isEmptyValBinds val_decls
then Nothing
else Just (ppr val_decls),
- ppr_ds tycl_decls, ppr_ds inst_decls,
+ ppr_ds (concat tycl_decls),
+ ppr_ds inst_decls,
ppr_ds deriv_decls,
ppr_ds foreign_decls]
where
diff --git a/compiler/hsSyn/HsUtils.lhs b/compiler/hsSyn/HsUtils.lhs
index d17f85099f..3ef4bff177 100644
--- a/compiler/hsSyn/HsUtils.lhs
+++ b/compiler/hsSyn/HsUtils.lhs
@@ -60,7 +60,7 @@ module HsUtils(
collectLStmtBinders, collectStmtBinders,
collectSigTysFromPats, collectSigTysFromPat,
- hsTyClDeclBinders, hsTyClDeclsBinders, hsConDeclsBinders,
+ hsTyClDeclBinders, hsTyClDeclsBinders,
hsForeignDeclsBinders, hsGroupBinders
) where
@@ -572,9 +572,10 @@ hsForeignDeclsBinders :: [LForeignDecl Name] -> [Name]
hsForeignDeclsBinders foreign_decls
= [n | L _ (ForeignImport (L _ n) _ _) <- foreign_decls]
-hsTyClDeclsBinders :: [Located (TyClDecl Name)] -> [Located (InstDecl Name)] -> [Name]
+hsTyClDeclsBinders :: [[LTyClDecl Name]] -> [Located (InstDecl Name)] -> [Name]
hsTyClDeclsBinders tycl_decls inst_decls
- = [n | d <- instDeclATs inst_decls ++ tycl_decls, L _ n <- hsTyClDeclBinders d]
+ = [n | d <- instDeclATs inst_decls ++ concat tycl_decls
+ , L _ n <- hsTyClDeclBinders d]
hsTyClDeclBinders :: Eq name => Located (TyClDecl name) -> [Located name]
-- ^ Returns all the /binding/ names of the decl, along with their SrcLocs.