Commit efc8ad15 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Give 'unboundName' a very low binding precedence

This fixes Trac #7937
parent b94e98a1
......@@ -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
......
......@@ -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
---------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment