diff options
author | simonpj@microsoft.com <unknown> | 2007-05-02 11:47:38 +0000 |
---|---|---|
committer | simonpj@microsoft.com <unknown> | 2007-05-02 11:47:38 +0000 |
commit | 72e37dedee9e8a109ebda4b13e49b7133b530591 (patch) | |
tree | 44fcd35a0359f193813f18f7983ec7c5a2fbbdeb /compiler/rename | |
parent | c94fac1c94f35f344edd6818db13a3fc021674b5 (diff) | |
download | haskell-72e37dedee9e8a109ebda4b13e49b7133b530591.tar.gz |
Improve error reporting for type signatures
See Trac #1310
Diffstat (limited to 'compiler/rename')
-rw-r--r-- | compiler/rename/RnBinds.lhs | 18 | ||||
-rw-r--r-- | compiler/rename/RnEnv.lhs | 19 |
2 files changed, 32 insertions, 5 deletions
diff --git a/compiler/rename/RnBinds.lhs b/compiler/rename/RnBinds.lhs index d7a5952ee2..1c7bebbd7d 100644 --- a/compiler/rename/RnBinds.lhs +++ b/compiler/rename/RnBinds.lhs @@ -33,12 +33,12 @@ import RnEnv ( bindLocatedLocalsRn, lookupLocatedBndrRn, warnUnusedLocalBinds, mapFvRn, extendTyVarEnvFVRn, ) import DynFlags ( DynFlag(..) ) -import Name ( Name, nameOccName, nameSrcLoc ) +import Name import NameEnv import NameSet import PrelNames ( isUnboundName ) import RdrName ( RdrName, rdrNameOcc ) -import SrcLoc ( mkSrcSpan, Located(..), unLoc ) +import SrcLoc ( Located(..), unLoc ) import ListSetOps ( findDupsEq ) import BasicTypes ( RecFlag(..) ) import Digraph ( SCC(..), stronglyConnComp ) @@ -629,10 +629,20 @@ dupSigDeclErr sigs@(L loc sig : _) ppr_sig (L loc sig) = ppr loc <> colon <+> ppr sig unknownSigErr (L loc sig) - = addErrAt loc $ - sep [ptext SLIT("Misplaced") <+> what_it_is <> colon, ppr sig] + = do { mod <- getModule + ; addErrAt loc $ + vcat [sep [ptext SLIT("Misplaced") <+> what_it_is <> colon, ppr sig], + extra_stuff mod sig] } where what_it_is = hsSigDoc sig + extra_stuff mod (TypeSig (L _ n) _) + | nameIsLocalOrFrom mod n + = ptext SLIT("The type signature must be given where") + <+> quotes (ppr n) <+> ptext SLIT("is declared") + | otherwise + = ptext SLIT("You cannot give a type signature for an imported value") + + extra_stuff mod other = empty methodBindErr mbind = hang (ptext SLIT("Pattern bindings (except simple variables) not allowed in instance declarations")) diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs index 50b0adb83c..54a768af26 100644 --- a/compiler/rename/RnEnv.lhs +++ b/compiler/rename/RnEnv.lhs @@ -195,8 +195,25 @@ lookupTopBndrRn rdr_name -- The Haskell98 report does not stipulate this, but it will! -- So we must treat the 'f' in the signature in the same way -- as the binding occurrence of 'f', using lookupBndrRn +-- +-- However, consider this case: +-- import M( f ) +-- f :: Int -> Int +-- g x = x +-- We don't want to say 'f' is out of scope; instead, we want to +-- return the imported 'f', so that later on the reanamer will +-- correctly report "misplaced type sig". lookupLocatedSigOccRn :: Located RdrName -> RnM (Located Name) -lookupLocatedSigOccRn = lookupLocatedBndrRn +lookupLocatedSigOccRn = wrapLocM $ \ rdr_name -> do + { local_env <- getLocalRdrEnv + ; case lookupLocalRdrEnv local_env rdr_name of { + Just n -> return n ; + Nothing -> do + { mb_gre <- lookupGreLocalRn rdr_name + ; case mb_gre of + Just gre -> return (gre_name gre) + Nothing -> lookupGlobalOccRn rdr_name + }}} -- lookupInstDeclBndr is used for the binders in an -- instance declaration. Here we use the class name to |