diff options
author | Paolo Capriotti <p.capriotti@gmail.com> | 2012-04-25 14:10:40 +0100 |
---|---|---|
committer | Paolo Capriotti <p.capriotti@gmail.com> | 2012-04-26 17:00:19 +0100 |
commit | 5bfd8933024cb2120c38e01346b1b47d6dde10cb (patch) | |
tree | d35fbbcc907f506ae18ed9040e3b718858e3943f /compiler/rename | |
parent | 9e3171c632d200ae1b259dd3501fa6f6d9ac3278 (diff) | |
download | haskell-5bfd8933024cb2120c38e01346b1b47d6dde10cb.tar.gz |
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.
Diffstat (limited to 'compiler/rename')
-rw-r--r-- | compiler/rename/RnEnv.lhs | 58 | ||||
-rw-r--r-- | compiler/rename/RnSource.lhs | 4 |
2 files changed, 42 insertions, 20 deletions
diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs index 85d77a6b73..9cb04ff47f 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] - where - occ = rdrNameOcc rdr_name + | isDataOcc occ || isVarOcc occ + = [rdr_name, rdr_name_tc] + | otherwise + = [rdr_name] + where + 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 ffd2910b45..8c338c810a 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") |