-importsFromLocalDecls :: HsGroup RdrName -> RnM TcGblEnv
-importsFromLocalDecls group
- = do { gbl_env <- getGblEnv
-
- ; avails <- getLocalDeclBinders gbl_env group
-
- ; rdr_env' <- extendRdrEnvRn (tcg_rdr_env gbl_env) avails
-
- ; traceRn (text "local avails: " <> ppr avails)
-
- ; returnM (gbl_env { tcg_rdr_env = rdr_env' })
- }
-
-extendRdrEnvRn :: GlobalRdrEnv -> [AvailInfo] -> RnM GlobalRdrEnv
--- Add the new locally-bound names one by one, checking for duplicates as
--- we do so. Remember that in Template Haskell the duplicates
--- might *already be* in the GlobalRdrEnv from higher up the module
-extendRdrEnvRn rdr_env avails
- = foldlM add_local rdr_env (gresFromAvails LocalDef avails)
+extendGlobalRdrEnvRn :: [AvailInfo]
+ -> MiniFixityEnv
+ -> RnM (TcGblEnv, TcLclEnv)
+ -- Updates both the GlobalRdrEnv and the FixityEnv
+ -- We return a new TcLclEnv only becuase we might have to
+ -- delete some bindings from it;
+ -- see Note [Top-level Names in Template Haskell decl quotes]
+
+extendGlobalRdrEnvRn avails new_fixities
+ = do { (gbl_env, lcl_env) <- getEnvs
+ ; stage <- getStage
+ ; let rdr_env = tcg_rdr_env gbl_env
+ fix_env = tcg_fix_env gbl_env
+
+ -- Delete new_occs from global and local envs
+ -- If we are in a TemplateHaskell decl bracket,
+ -- we are going to shadow them
+ -- See Note [Top-level Names in Template Haskell decl quotes]
+ shadowP = isBrackStage stage
+ new_occs = map (nameOccName . gre_name) gres
+ rdr_env1 = hideSomeUnquals rdr_env new_occs
+ lcl_env1 = lcl_env { tcl_rdr = delListFromOccEnv (tcl_rdr lcl_env) new_occs }
+ (rdr_env2, lcl_env2) | shadowP = (rdr_env1, lcl_env1)
+ | otherwise = (rdr_env, lcl_env)
+
+ rdr_env3 = foldl extendGlobalRdrEnv rdr_env2 gres
+ fix_env' = foldl extend_fix_env fix_env gres
+ (rdr_env', dups) = findLocalDupsRdrEnv rdr_env3 new_occs
+
+ gbl_env' = gbl_env { tcg_rdr_env = rdr_env', tcg_fix_env = fix_env' }
+
+ ; mapM_ addDupDeclErr dups
+
+ ; traceRn (text "extendGlobalRdrEnvRn" <+> (ppr new_fixities $$ ppr fix_env $$ ppr fix_env'))
+ ; return (gbl_env', lcl_env2) }