[commit: ghc] master: Give 'unboundName' a very low binding precedence (efc8ad1)

Simon Peyton Jones simonpj at microsoft.com
Tue May 28 10:25:21 CEST 2013


Repository : http://darcs.haskell.org/ghc.git/

On branch  : master

https://github.com/ghc/ghc/commit/efc8ad157fb0c1fda0d352a7bfebe2b2635e93d3

>---------------------------------------------------------------

commit efc8ad157fb0c1fda0d352a7bfebe2b2635e93d3
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Mon May 27 17:28:30 2013 +0100

    Give 'unboundName' a very low binding precedence
    
    This fixes Trac #7937

>---------------------------------------------------------------

 compiler/basicTypes/BasicTypes.lhs |  6 ++++--
 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 3501291..2445023 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 6db6011..ae0fbb9 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
 
 ---------------





More information about the ghc-commits mailing list