Commit 5bfd8933 authored by pcapriotti's avatar pcapriotti

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.
parent 9e3171c6
......@@ -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
......
......@@ -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")
......
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