git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Elaborate exports during renaming
5130603Gary Burgess
src/Language/PureScript/Sugar/Names.hs+14−3
@@ -147,9 +147,10 @@ desugarImports modules = do
147 -- the module has access to an unfiltered list of its own members.
147 -- the module has access to an unfiltered list of its own members.
148 renameInModule' :: ExportEnvironment -> ExportEnvironment -> Module -> Either String Module
148 renameInModule' :: ExportEnvironment -> ExportEnvironment -> Module -> Either String Module
149 renameInModule' unfilteredExports exports m@(Module mn _ _) = rethrowForModule m $ do
149 renameInModule' unfilteredExports exports m@(Module mn _ _) = rethrowForModule m $ do
150− let exports' = M.update (\_ -> M.lookup mn unfilteredExports) mn exports
150+ let env = M.update (\_ -> M.lookup mn unfilteredExports) mn exports
151+ let exps = fromMaybe (error "Module is missing in renameInModule'") $ M.lookup mn exports
151− imports <- resolveImports exports' m
152+ imports <- resolveImports env m
152− renameInModule imports exports' m
153+ renameInModule imports env (elaborateExports exps m)
153
154
154-- |
155-- |
155-- Rethrow an error with the name of the current module in the case of a failure
156-- Rethrow an error with the name of the current module in the case of a failure
@@ -157,6 +158,16 @@ desugarImports modules = do
157rethrowForModule :: Module -> Either String a -> Either String a
158rethrowForModule :: Module -> Either String a -> Either String a
158rethrowForModule (Module mn _ _) = flip catchError $ \e -> throwError ("Error in module '" ++ show mn ++ "':\n" ++ e)
159rethrowForModule (Module mn _ _) = flip catchError $ \e -> throwError ("Error in module '" ++ show mn ++ "':\n" ++ e)
159
160
161+-- |
162+-- Make all exports for a module explicit. This may still effect modules that have an exports list,
163+-- as it will also make all data constructor exports explicit.
164+--
165+elaborateExports :: Exports -> Module -> Module
166+elaborateExports exps (Module mn decls _) = Module mn decls (Just $
167+ map (\(ctor, dctors) -> TypeRef ctor (Just dctors)) (exportedTypes exps) ++
168+ map TypeClassRef (exportedTypeClasses exps) ++
169+ map ValueRef (exportedValues exps))
170+
160-- |
171-- |
161-- Replaces all local names with qualified names within a module and checks that all existing
172-- Replaces all local names with qualified names within a module and checks that all existing
162-- qualified names are valid.
173-- qualified names are valid.