@@ -15,6 +15,7 @@
1515{-# LANGUAGE RankNTypes #-}
1616{-# LANGUAGE ScopedTypeVariables #-}
1717{-# LANGUAGE TupleSections #-}
18+{-# LANGUAGE LambdaCase #-}
1819
1920module Language.PureScript.Sugar.Names.Exports
2021 ( findExportable
@@ -29,6 +30,7 @@ import Data.Maybe (fromMaybe, mapMaybe)
2930import Data.Foldable (traverse_)
3031
3132import Control.Monad
33+import Control.Monad.Writer.Class (MonadWriter(..))
3234import Control.Monad.Error.Class (MonadError(..))
3335
3436import qualified Data.Map as M
@@ -66,14 +68,31 @@ findExportable (Module _ _ mn ds _) =
6668-- Resolves the exports for a module, filtering out members that have not been
6769-- exported and elaborating re-exports of other modules.
6870--
69−resolveExports :: forall m. (Applicative m, MonadError MultipleErrors m) => Env -> ModuleName -> Imports -> Exports -> [DeclarationRef] -> m Exports
71+resolveExports :: forall m. (Applicative m, MonadError MultipleErrors m, MonadWriter MultipleErrors m) => Env -> ModuleName -> Imports -> Exports -> [DeclarationRef] -> m Exports
7072resolveExports env mn imps exps refs =
7173 rethrow (addHint (ErrorInModule mn)) $ do
7274 filtered <- filterModule mn exps refs
75+ let (dupeRefs, dupeDctors) = findDuplicateRefs refs
76+ warnDupeRefs dupeRefs
77+ warnDupeDctors dupeDctors
7378 foldM elaborateModuleExports filtered refs
7479
7580 where
7681
82+ warnDupeRefs :: [DeclarationRef] -> m ()
83+ warnDupeRefs = traverse_ $ \case
84+ TypeRef name _ -> warnDupe $ "type " ++ runProperName name
85+ ValueRef name -> warnDupe $ "value " ++ runIdent name
86+ TypeClassRef name -> warnDupe $ "class " ++ runProperName name
87+ ModuleRef name -> warnDupe $ "module " ++ runModuleName name
88+ _ -> return ()
89+
90+ warnDupeDctors :: [ProperName] -> m ()
91+ warnDupeDctors = traverse_ (warnDupe . ("data constructor " ++) . runProperName)
92+
93+ warnDupe :: String -> m ()
94+ warnDupe ref = tell . errorMessage $ DuplicateExportRef ref
95+
7796 -- Takes the current module's imports, the accumulated list of exports, and a
7897 -- `DeclarationRef` for an explicit export. When the ref refers to another
7998 -- module, export anything from the imports that matches for that module.