- Nothing -> failWithRn emptyAvailEnv (modExportErr mod)
- Just avails -> listToAvailEnv ie avails
-
- exports_from_item ie
- | not (maybeToBool maybe_in_scope)
- = failWithRn emptyAvailEnv (unknownNameErr (ieName ie))
-
-#ifdef DEBUG
- -- I can't see why this should ever happen; if the thing is in scope
- -- at all it ought to have some availability
- | not (maybeToBool maybe_avail)
- = pprTrace "exportsFromAvail: curious Nothing:" (ppr PprDebug name)
- returnRn emptyAvailEnv
-#endif
-
- | not enough_avail
- = failWithRn emptyAvailEnv (exportItemErr ie export_avail)
-
- | otherwise -- Phew! It's OK!
- = returnRn (unitAvailEnv ie export_avail)
- where
- maybe_in_scope = lookupNameEnv name_env (ieName ie)
- Just name = maybe_in_scope
- maybe_avail = lookupUFM entity_avail_env name
- Just avail = maybe_avail
- export_avail = filterAvail ie avail
- enough_avail = case export_avail of {NotAvailable -> False; other -> True}
-
- -- We export a fixity iff we export a thing with the same (qualified) RdrName
- mk_exported_fixities :: NameSet -> [(OccName, (Fixity, Provenance))]
- mk_exported_fixities exports
- = fmToList (foldr (perhaps_add_fixity exports)
- emptyFM
- (fmToList fixity_env))
-
- perhaps_add_fixity :: NameSet -> (RdrName, (Fixity, Provenance))
- -> FiniteMap OccName (Fixity,Provenance)
- -> FiniteMap OccName (Fixity,Provenance)
- perhaps_add_fixity exports (rdr_name, (fixity, prov)) fix_env
- = let
- do_nothing = fix_env -- The default is to pass on the env unchanged
- in
- -- Step 1: check whether the rdr_name is in scope; if so find its Name
- case lookupFM name_env rdr_name of {
- Nothing -> do_nothing;
- Just fixity_name ->
-
- -- Step 2: check whether the fixity thing is exported
- if not (fixity_name `elemNameSet` exports) then
- do_nothing
- else
-
- -- Step 3: check whether we already have a fixity for the
- -- Name's OccName in the fix_env we are building up. This can easily
- -- happen. the original fixity_env might contain bindings for
- -- M.a and N.a, if a was imported via M and N.
- -- If this does happen, we expect the fixity to be the same either way.
- let
- occ_name = rdrNameOcc rdr_name
- in
- case lookupFM fix_env occ_name of {
- Just (fixity1, prov1) -> -- Got it already
- ASSERT( fixity == fixity1 )
- do_nothing;
- Nothing ->
-
- -- Step 3: add it to the outgoing fix_env
- addToFM fix_env occ_name (fixity,prov)
- }}
-
-mk_export_fn :: [AvailInfo] -> (Name -> ExportFlag)
-mk_export_fn avails
- = \name -> if name `elemNameSet` exported_names
- then Exported
- else NotExported
+ Nothing -> failWithRn acc (modExportErr mod)
+ Just mod_avails -> foldlRn (check_occs ie) occs mod_avails
+ `thenRn` \ occs' ->
+ let
+ avails' = foldl addAvail avails mod_avails
+ in
+ returnRn (mod:mods, occs', avails')
+
+ exports_from_item warn_dups acc@(mods, occs, avails) ie
+ = lookupSrcName global_name_env (ieName ie) `thenRn` \ name ->
+
+ -- See what's available in the current environment
+ case lookupUFM entity_avail_env name of {
+ Nothing -> -- Presumably this happens because lookupSrcName didn't find
+ -- the name and returned an unboundName, which won't be in
+ -- the entity_avail_env, of course
+ WARN( not (isUnboundName name), ppr name )
+ returnRn acc ;
+
+ Just avail ->
+
+ -- Filter out the bits we want
+ case filterAvail ie avail of {
+ Nothing -> -- Not enough availability
+ failWithRn acc (exportItemErr ie) ;
+
+ Just export_avail ->
+
+ -- Phew! It's OK! Now to check the occurrence stuff!
+ warnCheckRn (ok_item ie avail) (dodgyExportWarn ie) `thenRn_`
+ check_occs ie occs export_avail `thenRn` \ occs' ->
+ returnRn (mods, occs', addAvail avails export_avail)
+ }}
+
+
+
+ok_item (IEThingAll _) (AvailTC _ [n]) = False
+ -- This occurs when you import T(..), but
+ -- only export T abstractly. The single [n]
+ -- in the AvailTC is the type or class itself
+ok_item _ _ = True
+
+check_occs :: RdrNameIE -> ExportOccMap -> AvailInfo -> RnMG ExportOccMap
+check_occs ie occs avail
+ = doptRn Opt_WarnDuplicateExports `thenRn` \ warn_dup_exports ->
+ foldlRn (check warn_dup_exports) occs (availNames avail)