diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2013-05-27 17:28:30 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2013-05-28 09:25:08 +0100 |
commit | efc8ad157fb0c1fda0d352a7bfebe2b2635e93d3 (patch) | |
tree | 9c88f5044b2aeb4346839fb70f9288a8d89ca882 | |
parent | b94e98a10629d7a35b5e28c63d41209aa33acbbd (diff) | |
download | haskell-efc8ad157fb0c1fda0d352a7bfebe2b2635e93d3.tar.gz |
Give 'unboundName' a very low binding precedence
This fixes Trac #7937
-rw-r--r-- | compiler/basicTypes/BasicTypes.lhs | 6 | ||||
-rw-r--r-- | compiler/rename/RnEnv.lhs | 42 |
2 files changed, 31 insertions, 17 deletions
diff --git a/compiler/basicTypes/BasicTypes.lhs b/compiler/basicTypes/BasicTypes.lhs index 3501291557..2445023b8f 100644 --- a/compiler/basicTypes/BasicTypes.lhs +++ b/compiler/basicTypes/BasicTypes.lhs @@ -37,7 +37,7 @@ module BasicTypes( WarningTxt(..), Fixity(..), FixityDirection(..), - defaultFixity, maxPrecedence, + defaultFixity, maxPrecedence, minPrecedence, negateFixity, funTyFixity, compareFixity, @@ -251,8 +251,10 @@ instance Outputable FixityDirection where ppr InfixN = ptext (sLit "infix") ------------------------ -maxPrecedence :: Int +maxPrecedence, minPrecedence :: Int maxPrecedence = 9 +minPrecedence = 0 + defaultFixity :: Fixity defaultFixity = Fixity maxPrecedence InfixL diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs index 6db6011656..ae0fbb99b2 100644 --- a/compiler/rename/RnEnv.lhs +++ b/compiler/rename/RnEnv.lhs @@ -57,8 +57,9 @@ import Module import UniqFM import DataCon ( dataConFieldLabels, dataConTyCon ) import TyCon ( isTupleTyCon, tyConArity ) -import PrelNames ( mkUnboundName, rOOT_MAIN, forall_tv_RDR ) +import PrelNames ( mkUnboundName, isUnboundName, rOOT_MAIN, forall_tv_RDR ) import ErrUtils ( MsgDoc ) +import BasicTypes ( Fixity(..), FixityDirection(..), minPrecedence ) import SrcLoc import Outputable import Util @@ -1083,15 +1084,26 @@ lookupFixity is a bit strange. \begin{code} lookupFixityRn :: Name -> RnM Fixity -lookupFixityRn name = do - this_mod <- getModule - if nameIsLocalOrFrom this_mod name - then do -- It's defined in this module - local_fix_env <- getFixityEnv - traceRn (text "lookupFixityRn: looking up name in local environment:" <+> - vcat [ppr name, ppr local_fix_env]) - return $ lookupFixity local_fix_env name - else -- It's imported +lookupFixityRn name + | isUnboundName name + = return (Fixity minPrecedence InfixL) + -- Minimise errors from ubound names; eg + -- a>0 `foo` b>0 + -- where 'foo' is not in scope, should not give an error (Trac #7937) + + | otherwise + = do { this_mod <- getModule + ; if nameIsLocalOrFrom this_mod name + then lookup_local + else lookup_imported } + where + lookup_local -- It's defined in this module + = do { local_fix_env <- getFixityEnv + ; traceRn (text "lookupFixityRn: looking up name in local environment:" <+> + vcat [ppr name, ppr local_fix_env]) + ; return (lookupFixity local_fix_env name) } + + lookup_imported -- For imported names, we have to get their fixities by doing a -- loadInterfaceForName, and consulting the Ifaces that comes back -- from that, because the interface file for the Name might not @@ -1108,11 +1120,11 @@ lookupFixityRn name = do -- -- loadInterfaceForName will find B.hi even if B is a hidden module, -- and that's what we want. - do iface <- loadInterfaceForName doc name - traceRn (text "lookupFixityRn: looking up name in iface cache and found:" <+> - vcat [ppr name, ppr $ mi_fix_fn iface (nameOccName name)]) - return (mi_fix_fn iface (nameOccName name)) - where + = do { iface <- loadInterfaceForName doc name + ; traceRn (text "lookupFixityRn: looking up name in iface cache and found:" <+> + vcat [ppr name, ppr $ mi_fix_fn iface (nameOccName name)]) + ; return (mi_fix_fn iface (nameOccName name)) } + doc = ptext (sLit "Checking fixity for") <+> ppr name --------------- |