diff options
author | simonpj@microsoft.com <unknown> | 2009-04-09 14:40:04 +0000 |
---|---|---|
committer | simonpj@microsoft.com <unknown> | 2009-04-09 14:40:04 +0000 |
commit | 6c06fdc7ad20682f0f52b5a78e5e3487a2ed047b (patch) | |
tree | 0374328ec7816d5669311b1740381617f7709ed7 /compiler/rename | |
parent | f0c99958649b8909612b1b9c9b48aad970dfce05 (diff) | |
download | haskell-6c06fdc7ad20682f0f52b5a78e5e3487a2ed047b.tar.gz |
Fix Trac #3155: better error message when -XRankNTypes is omitted
This patch sligtly re-adjusts the way in which the syntax of types
is handled:
* In the lexer, '.' and '*' are always accepted in types
(previously it was conditional). This things can't mean
anything else in H98, which is the only reason for doing things
conditionally in the lexer.
* As a result '.' in types is never treated as an operator.
Instead, lacking a 'forall' keyword, it turns into a plain parse error.
* Test for -XKindSignatures in the renamer when processing
a) type variable bindings
b) types with sigs (ty :: kind-sig)
* Make -XKindSignatures be implied by -XTypeFamilies
Previously this was buried in the conditonal lexing of '*'
Diffstat (limited to 'compiler/rename')
-rw-r--r-- | compiler/rename/RnEnv.lhs | 24 | ||||
-rw-r--r-- | compiler/rename/RnTypes.lhs | 8 |
2 files changed, 21 insertions, 11 deletions
diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs index 72ec8c4708..56f18ab763 100644 --- a/compiler/rename/RnEnv.lhs +++ b/compiler/rename/RnEnv.lhs @@ -30,7 +30,7 @@ module RnEnv ( mapFvRn, mapFvRnCPS, warnUnusedMatches, warnUnusedModules, warnUnusedImports, warnUnusedTopBinds, warnUnusedLocalBinds, - dataTcOccs, unknownNameErr, perhapsForallMsg, + dataTcOccs, unknownNameErr, kindSigErr, perhapsForallMsg, checkM ) where @@ -824,13 +824,15 @@ bindTyVarsRn :: SDoc -> [LHsTyVarBndr RdrName] -> RnM a -- Haskell-98 binding of type variables; e.g. within a data type decl bindTyVarsRn doc_str tyvar_names enclosed_scope - = let - located_tyvars = hsLTyVarLocNames tyvar_names - in - bindLocatedLocalsRn doc_str located_tyvars $ \ names -> - enclosed_scope (zipWith replace tyvar_names names) - where - replace (L loc n1) n2 = L loc (replaceTyVarName n1 n2) + = bindLocatedLocalsRn doc_str located_tyvars $ \ names -> + do { kind_sigs_ok <- doptM Opt_KindSignatures + ; checkM (null kinded_tyvars || kind_sigs_ok) + (mapM_ (addErr . kindSigErr) kinded_tyvars) + ; enclosed_scope (zipWith replace tyvar_names names) } + where + replace (L loc n1) n2 = L loc (replaceTyVarName n1 n2) + located_tyvars = hsLTyVarLocNames tyvar_names + kinded_tyvars = [n | L _ (KindedTyVar n _) <- tyvar_names] bindPatSigTyVars :: [LHsType RdrName] -> ([Name] -> RnM a) -> RnM a -- Find the type variables in the pattern type @@ -1087,6 +1089,12 @@ dupNamesErr get_loc descriptor names | otherwise = ptext (sLit "Bound at:") <+> vcat (map ppr (sortLe (<=) locs)) +kindSigErr :: Outputable a => a -> SDoc +kindSigErr thing + = hang (ptext (sLit "Illegal kind signature for") <+> quotes (ppr thing)) + 2 (ptext (sLit "Perhaps you intended to use -XKindSignatures")) + + badQualBndrErr :: RdrName -> SDoc badQualBndrErr rdr_name = ptext (sLit "Qualified name in binding position:") <+> ppr rdr_name diff --git a/compiler/rename/RnTypes.lhs b/compiler/rename/RnTypes.lhs index d5fc150904..4f9672bb8c 100644 --- a/compiler/rename/RnTypes.lhs +++ b/compiler/rename/RnTypes.lhs @@ -148,9 +148,11 @@ rnHsType doc (HsListTy ty) = do ty' <- rnLHsType doc ty return (HsListTy ty') -rnHsType doc (HsKindSig ty k) = do - ty' <- rnLHsType doc ty - return (HsKindSig ty' k) +rnHsType doc (HsKindSig ty k) + = do { kind_sigs_ok <- doptM Opt_KindSignatures + ; checkM kind_sigs_ok (addErr (kindSigErr ty)) + ; ty' <- rnLHsType doc ty + ; return (HsKindSig ty' k) } rnHsType doc (HsPArrTy ty) = do ty' <- rnLHsType doc ty |