Ticket #6027: 6027.patch

File 6027.patch, 4.7 KB (added by pcapriotti, 3 years ago)
  • compiler/rename/RnEnv.lhs

    From aca58c33ce4cab5e29ce672e5ad44278c8333c71 Mon Sep 17 00:00:00 2001
    From: Paolo Capriotti <[email protected]>
    Date: Wed, 25 Apr 2012 14:10:40 +0100
    Subject: [PATCH] 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    |   55 +++++++++++++++++++++++++++--------------
     compiler/rename/RnSource.lhs |    4 +-
     2 files changed, 38 insertions(+), 21 deletions(-)
    
    diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs
    index 85d77a6..050c7ea 100644
    a b module RnEnv ( 
    1919        lookupTypeOccRn, lookupKindOccRn,
    2020        lookupGlobalOccRn, lookupGlobalOccRn_maybe,
    2121
    22         HsSigCtxt(..), lookupLocalDataTcNames, lookupSigOccRn,
     22        HsSigCtxt(..), lookupLocalTcNames, lookupSigOccRn,
    2323
    2424        lookupFixityRn, lookupTyFixityRn,
    2525        lookupInstDeclBndr, lookupSubBndrOcc, lookupFamInstName,
    lookupBindGroupOcc ctxt what rdr_name 
    927927
    928928
    929929---------------
    930 lookupLocalDataTcNames :: NameSet -> SDoc -> RdrName -> RnM [Name]
    931 -- GHC extension: look up both the tycon and data con
    932 -- for con-like things.  Used for top-level fixity signatures
    933 -- Complain if neither is in scope
    934 lookupLocalDataTcNames bndr_set what rdr_name
     930lookupLocalTcNames :: NameSet -> SDoc -> RdrName -> RnM [Name]
     931-- GHC extension: look up both the tycon and data con or variable.
     932-- Used for top-level fixity signatures. Complain if neither is in scope.
     933-- See Note [Fixity signature lookup]
     934lookupLocalTcNames bndr_set what rdr_name
    935935  | Just n <- isExact_maybe rdr_name   
    936936        -- Special case for (:), which doesn't get into the GlobalRdrEnv
    937937  = do { n' <- lookupExactOcc n; return [n'] }  -- For this we don't need to try the tycon too
    938938  | otherwise
    939   = do  { mb_gres <- mapM (lookupBindGroupOcc (LocalBindCtxt bndr_set) what)
    940                           (dataTcOccs rdr_name)
    941         ; let (errs, names) = splitEithers mb_gres
    942         ; when (null names) (addErr (head errs))        -- Bleat about one only
    943         ; return names }
     939  = do { mb_gres <- mapM lookup (dataTcOccs rdr_name)
     940       ; let (errs, names) = splitEithers mb_gres
     941       ; when (null names) $ addErr (head errs) -- Bleat about one only
     942       ; return names }
     943  where
     944    lookup = lookupBindGroupOcc (LocalBindCtxt bndr_set) what
    944945
    945946dataTcOccs :: RdrName -> [RdrName]
    946 -- If the input is a data constructor, return both it and a type
    947 -- constructor.  This is useful when we aren't sure which we are
    948 -- looking at.
    949 dataTcOccs rdr_name
    950   | isDataOcc occ             = [rdr_name, rdr_name_tc]
    951   | otherwise                 = [rdr_name]
    952   where   
    953     occ         = rdrNameOcc rdr_name
     947-- Return both the given name and the same name promoted to the TcClsName
     948-- namespace.  This is useful when we aren't sure which we are looking at.
     949dataTcOccs rdr_name = [rdr_name, rdr_name_tc]
     950  where
    954951    rdr_name_tc = setRdrNameSpace rdr_name tcName
    955952\end{code}
    956953
    dataTcOccs rdr_name 
    961958%*                                                      *
    962959%*********************************************************
    963960
     961Note [Fixity signature lookup]
     962~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     963A fixity declaration like
     964
     965    infixr 2 ?
     966
     967can refer to a value-level operator, e.g.:
     968
     969    (?) :: String -> String -> String
     970
     971or a type-level operator, like:
     972
     973    data (?) a b = A a | B b
     974
     975so we extend the lookup of the reader name '?' to the TcClsName namespace, as
     976well as the original namespace.
     977
     978The extended lookup is also used in other places, like resolution of
     979deprecation declarations, and lookup of names in GHCi.
     980
    964981\begin{code}
    965982--------------------------------
    966983type FastStringEnv a = UniqFM a         -- Keyed by FastString
  • compiler/rename/RnSource.lhs

    diff --git a/compiler/rename/RnSource.lhs b/compiler/rename/RnSource.lhs
    index ffd2910..8c338c8 100644
    a b rnSrcFixityDecls bndr_set fix_decls 
    269269    rn_decl (L loc (FixitySig (L name_loc rdr_name) fixity))
    270270      = setSrcSpan name_loc $
    271271                    -- this lookup will fail if the definition isn't local
    272         do names <- lookupLocalDataTcNames bndr_set what rdr_name
     272        do names <- lookupLocalTcNames bndr_set what rdr_name
    273273           return [ L loc (FixitySig (L name_loc name) fixity)
    274274                  | name <- names ]
    275275    what = ptext (sLit "fixity signature")
    rnSrcWarnDecls bndr_set decls 
    304304 where
    305305   rn_deprec (Warning rdr_name txt)
    306306       -- ensures that the names are defined locally
    307      = do { names <- lookupLocalDataTcNames bndr_set what rdr_name
     307     = do { names <- lookupLocalTcNames bndr_set what rdr_name
    308308          ; return [(nameOccName name, txt) | name <- names] }
    309309   
    310310   what = ptext (sLit "deprecation")