Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/5bfd8933024cb2120c38e01346b1b47d6dde10cb

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

commit 5bfd8933024cb2120c38e01346b1b47d6dde10cb
Author: Paolo Capriotti <[email protected]>
Date:   Wed Apr 25 14:10:40 2012 +0100

    Fix lookup of fixity signatures for type operators (#6027)
    
    Extend name lookup for fixity declaration to the TcClsName namespace for
    all reader names, instead of only those in DataName.

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

 compiler/rename/RnEnv.lhs    |   56 +++++++++++++++++++++++++++++------------
 compiler/rename/RnSource.lhs |    4 +-
 2 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs
index 85d77a6..9cb04ff 100644
--- a/compiler/rename/RnEnv.lhs
+++ b/compiler/rename/RnEnv.lhs
@@ -19,7 +19,7 @@ module RnEnv (
         lookupTypeOccRn, lookupKindOccRn, 
         lookupGlobalOccRn, lookupGlobalOccRn_maybe,
 
-       HsSigCtxt(..), lookupLocalDataTcNames, lookupSigOccRn,
+       HsSigCtxt(..), lookupLocalTcNames, lookupSigOccRn,
 
        lookupFixityRn, lookupTyFixityRn, 
        lookupInstDeclBndr, lookupSubBndrOcc, lookupFamInstName,
@@ -927,30 +927,32 @@ lookupBindGroupOcc ctxt what rdr_name
 
 
 ---------------
-lookupLocalDataTcNames :: NameSet -> SDoc -> RdrName -> RnM [Name]
--- GHC extension: look up both the tycon and data con 
--- for con-like things.  Used for top-level fixity signatures
--- Complain if neither is in scope
-lookupLocalDataTcNames bndr_set what rdr_name
+lookupLocalTcNames :: NameSet -> SDoc -> RdrName -> RnM [Name]
+-- GHC extension: look up both the tycon and data con or variable.
+-- Used for top-level fixity signatures. Complain if neither is in scope.
+-- See Note [Fixity signature lookup]
+lookupLocalTcNames bndr_set what rdr_name
   | Just n <- isExact_maybe rdr_name   
        -- Special case for (:), which doesn't get into the GlobalRdrEnv
   = do { n' <- lookupExactOcc n; return [n'] } -- For this we don't need to 
try the tycon too
   | otherwise
-  = do { mb_gres <- mapM (lookupBindGroupOcc (LocalBindCtxt bndr_set) what)
-                         (dataTcOccs rdr_name)
-       ; let (errs, names) = splitEithers mb_gres
-       ; when (null names) (addErr (head errs))        -- Bleat about one only
-       ; return names }
+  = do { mb_gres <- mapM lookup (dataTcOccs rdr_name)
+       ; let (errs, names) = splitEithers mb_gres
+       ; when (null names) $ addErr (head errs) -- Bleat about one only
+       ; return names }
+  where
+    lookup = lookupBindGroupOcc (LocalBindCtxt bndr_set) what
 
 dataTcOccs :: RdrName -> [RdrName]
--- If the input is a data constructor, return both it and a type
--- constructor.  This is useful when we aren't sure which we are
--- looking at.
+-- Return both the given name and the same name promoted to the TcClsName
+-- namespace.  This is useful when we aren't sure which we are looking at.
 dataTcOccs rdr_name
-  | isDataOcc occ            = [rdr_name, rdr_name_tc]
-  | otherwise                = [rdr_name]
+  | isDataOcc occ || isVarOcc occ
+  = [rdr_name, rdr_name_tc]
+  | otherwise
+  = [rdr_name]
   where    
-    occ        = rdrNameOcc rdr_name
+    occ = rdrNameOcc rdr_name
     rdr_name_tc = setRdrNameSpace rdr_name tcName
 \end{code}
 
@@ -961,6 +963,26 @@ dataTcOccs rdr_name
 %*                                                     *
 %*********************************************************
 
+Note [Fixity signature lookup]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+A fixity declaration like
+
+    infixr 2 ?
+
+can refer to a value-level operator, e.g.:
+
+    (?) :: String -> String -> String
+
+or a type-level operator, like:
+
+    data (?) a b = A a | B b
+
+so we extend the lookup of the reader name '?' to the TcClsName namespace, as
+well as the original namespace.
+
+The extended lookup is also used in other places, like resolution of
+deprecation declarations, and lookup of names in GHCi.
+
 \begin{code}
 --------------------------------
 type FastStringEnv a = UniqFM a                -- Keyed by FastString
diff --git a/compiler/rename/RnSource.lhs b/compiler/rename/RnSource.lhs
index ffd2910..8c338c8 100644
--- a/compiler/rename/RnSource.lhs
+++ b/compiler/rename/RnSource.lhs
@@ -269,7 +269,7 @@ rnSrcFixityDecls bndr_set fix_decls
     rn_decl (L loc (FixitySig (L name_loc rdr_name) fixity))
       = setSrcSpan name_loc $
                     -- this lookup will fail if the definition isn't local
-        do names <- lookupLocalDataTcNames bndr_set what rdr_name
+        do names <- lookupLocalTcNames bndr_set what rdr_name
            return [ L loc (FixitySig (L name_loc name) fixity)
                   | name <- names ]
     what = ptext (sLit "fixity signature")
@@ -304,7 +304,7 @@ rnSrcWarnDecls bndr_set decls
  where
    rn_deprec (Warning rdr_name txt)
        -- ensures that the names are defined locally
-     = do { names <- lookupLocalDataTcNames bndr_set what rdr_name
+     = do { names <- lookupLocalTcNames bndr_set what rdr_name
           ; return [(nameOccName name, txt) | name <- names] }
    
    what = ptext (sLit "deprecation")



_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to