- import_fm :: FiniteMap OccName RdrNameIE
- import_fm = listToFM [(ieOcc ie, ie) | ie <- import_items]
-
- avail_fm :: FiniteMap OccName AvailInfo
- avail_fm = listToFM [(nameOccName name, avail) | avail@(Avail name ns) <- avails]
-
- new_avail NotAvailable = NotAvailable
- new_avail avail@(Avail name _)
- | not in_import_items && want_hiding = avail
- | not in_import_items && not want_hiding = NotAvailable
- | in_import_items && want_hiding = NotAvailable
- | in_import_items && not want_hiding = filtered_avail
- where
- maybe_import_item = lookupFM import_fm (nameOccName name)
- in_import_items = maybeToBool maybe_import_item
- Just import_item = maybe_import_item
- filtered_avail = filterAvail import_item avail
-
- check_import_item :: RdrNameIE -> RnMG ()
- check_import_item item
- = checkRn (maybeToBool maybe_matching_avail && sub_names_ok item avail)
- (badImportItemErr mod item)
- where
- item_name = ieOcc item
- maybe_matching_avail = lookupFM avail_fm item_name
- Just avail = maybe_matching_avail
-
- sub_names_ok (IEVar _) _ = True
- sub_names_ok (IEThingAbs _) _ = True
- sub_names_ok (IEThingAll _) _ = True
- sub_names_ok (IEThingWith _ wanted) (Avail _ has) = all ((`elem` has_list) . rdrNameOcc) wanted
- where
- has_list = map nameOccName has
- sub_names_ok other1 other2 = False
+ import_fm :: FiniteMap OccName AvailInfo
+ import_fm = listToFM [ (nameOccName name, avail)
+ | avail <- total_avails,
+ name <- availNames avail]
+ -- Even though availNames returns data constructors too,
+ -- they won't make any difference because naked entities like T
+ -- in an import list map to TcOccs, not VarOccs.
+
+ bale_out item = addErrRn (badImportItemErr mod from item) `thenRn_`
+ returnRn []
+
+ get_item :: RdrNameIE -> RnMG [(AvailInfo, [Name])]
+ get_item item@(IEModuleContents _) = bale_out item
+
+ get_item item@(IEThingAll _)
+ = case check_item item of
+ Nothing -> bale_out item
+ Just avail@(AvailTC _ [n]) -> -- This occurs when you import T(..), but
+ -- only export T abstractly. The single [n]
+ -- in the AvailTC is the type or class itself
+ ifOptRn Opt_WarnMisc (addWarnRn (dodgyImportWarn mod item)) `thenRn_`
+ returnRn [(avail, [availName avail])]
+ Just avail -> returnRn [(avail, [availName avail])]
+
+ get_item item@(IEThingAbs n)
+ | want_hiding -- hiding( C )
+ -- Here the 'C' can be a data constructor *or* a type/class
+ = case catMaybes [check_item item, check_item (IEVar data_n)] of
+ [] -> bale_out item
+ avails -> returnRn [(a, []) | a <- avails]
+ -- The 'explicits' list is irrelevant when hiding
+ where
+ data_n = setRdrNameOcc n (setOccNameSpace (rdrNameOcc n) dataName)
+
+ get_item item
+ = case check_item item of
+ Nothing -> bale_out item
+ Just avail -> returnRn [(avail, availNames avail)]
+
+ check_item item
+ | not (maybeToBool maybe_in_import_avails) ||
+ not (maybeToBool maybe_filtered_avail)
+ = Nothing
+
+ | otherwise
+ = Just filtered_avail
+
+ where
+ wanted_occ = rdrNameOcc (ieName item)
+ maybe_in_import_avails = lookupFM import_fm wanted_occ
+
+ Just avail = maybe_in_import_avails
+ maybe_filtered_avail = filterAvail item avail
+ Just filtered_avail = maybe_filtered_avail