git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Disallow duplicate module definitions
commit13849b6b26aaac766c3ca1fa7f8260b3c0d05146 authorGary Burgess <gary.burgess@gmail.com> dateTue 11 Mar 2014, 22:57 (13 years ago) parent5e845ad
1 file changed+8−3
src/Language/PureScript/Sugar/Names.hs+8−3
src/Language/PureScript/Sugar/Names.hs+8−3
@@ -89,8 +89,11 @@ updateExportedModule env mn update = do
8989-- |
9090-- Adds an empty module to an ExportEnvironment.
9191--
92−addEmptyModule :: ExportEnvironment -> ModuleName -> ExportEnvironment
93−addEmptyModule env name = M.insert name (Exports [] [] []) env
92+addEmptyModule :: ExportEnvironment -> ModuleName -> Either String ExportEnvironment
93+addEmptyModule env name =
94+ if name `M.member` env
95+ then throwError $ "Module '" ++ show name ++ "' has been defined more than once"
96+ else return $ M.insert name (Exports [] [] []) env
9497
9598-- |
9699-- Adds a type belonging to a module to the export environment.
@@ -255,7 +258,9 @@ findExports = foldM addModule $ M.singleton (ModuleName [ProperName "Prim"]) pri
255258
256259 -- Add all of the exported declarations from a module to the global export environment
257260 addModule :: ExportEnvironment -> Module -> Either String ExportEnvironment
258− addModule env m@(Module mn ds _) = rethrowForModule m $ foldM (addDecl mn) (addEmptyModule env mn) ds
261+ addModule env m@(Module mn ds _) = do
262+ env' <- addEmptyModule env mn
263+ rethrowForModule m $ foldM (addDecl mn) env' ds
259264
260265 -- Add a declaration from a module to the global export environment
261266 addDecl :: ModuleName -> ExportEnvironment -> Declaration -> Either String ExportEnvironment