@@ -468,10 +468,13 @@ filterExports mn exps env = do
468468-- Finds the imports within a module, mapping the imported module name to an optional set of
469469-- explicitly imported declarations.
470470--
471−findImports :: [Declaration] -> M.Map ModuleName (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)
471+findImports :: [Declaration] -> M.Map ModuleName [(Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)]
472472findImports = foldl (findImports' Nothing) M.empty
473473 where
474− findImports' pos result (ImportDeclaration mn typ qual) = M.insert mn (pos, typ, qual) result
474+ findImports' pos result (ImportDeclaration mn typ qual) =
475+ case mn `M.lookup` result of
476+ Just is -> M.insert mn ((pos, typ, qual):is) result
477+ Nothing -> M.insert mn [(pos, typ, qual)] result
475478 findImports' _ result (PositionedDeclaration pos _ d) = findImports' (Just pos) result d
476479 findImports' _ result _ = result
477480
@@ -486,17 +489,20 @@ resolveImports env (Module _ _ currentModule decls _) =
486489 -- A Map from module name to the source position for the import, the list of imports from that
487490 -- module (where Nothing indicates everything is to be imported), and optionally a qualified name
488491 -- for the module
489− scope :: M.Map ModuleName (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)
490− scope = M.insert currentModule (Nothing, Implicit, Nothing) (findImports decls)
492+ scope :: M.Map ModuleName [(Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)]
493+ scope = M.insert currentModule [(Nothing, Implicit, Nothing)] (findImports decls)
491494
492− resolveImport' :: ImportEnvironment -> (ModuleName, (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)) -> m ImportEnvironment
493− resolveImport' imp (mn, (pos, typ, impQual)) = do
494− modExports <- positioned $ maybe (throwError . errorMessage $ UnknownModule mn) return $ mn `M.lookup` env
495− positioned $ resolveImport currentModule mn modExports imp impQual typ
495+ resolveImport' :: ImportEnvironment -> (ModuleName, [(Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName)]) -> m ImportEnvironment
496+ resolveImport' ie (mn, imps) = foldM go ie imps
496497 where
497− positioned err = case pos of
498− Nothing -> err
499− Just pos' -> rethrowWithPosition pos' err
498+ go :: ImportEnvironment -> (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName) -> m ImportEnvironment
499+ go ie' (pos, typ, impQual) = do
500+ modExports <- positioned $ maybe (throwError . errorMessage $ UnknownModule mn) return $ mn `M.lookup` env
501+ positioned $ resolveImport currentModule mn modExports ie' impQual typ
502+ where
503+ positioned err = case pos of
504+ Nothing -> err
505+ Just pos' -> rethrowWithPosition pos' err
500506
501507-- |
502508-- Extends the local environment for a module by resolving an import of another module.