git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix warning about values missing from virtual modules
commit86acebbe3a0fb7cbc203d2ce45b223a228a78168 authorGary Burgess <gary.burgess@gmail.com> dateFri 25 Dec 2015, 03:21 (11 years ago) parent6f88b74
4 files changed+35−7
examples/failing/1733.purs+13 src/Language/PureScript/Sugar/Names.hs+8−3 src/Language/PureScript/Sugar/Names/Env.hs+9−3 src/Language/PureScript/Sugar/Names/Imports.hs+5−1
examples/failing/1733.pursnew file+13
@@ -0,0 +1,13 @@
1+-- @shouldFailWith UnknownValue
2+
3+module Main where
4+
5+import Thingy as Thing
6+
7+main = Thing.doesntExist "hi"
8+
9+module Thingy where
10+
11+foo :: Int
12+foo = 1
13+
src/Language/PureScript/Sugar/Names.hs+8−3
@@ -16,6 +16,7 @@ import Control.Monad.Writer (MonadWriter(..), censor)
1616import Control.Monad.State.Lazy
1717
1818import qualified Data.Map as M
19+import qualified Data.Set as S
1920
2021import Language.PureScript.Crash
2122import Language.PureScript.AST
@@ -257,17 +258,21 @@ renameInModule env imports (Module ss coms mn decls exps) =
257258 -- by qualified importing). If that's not the case, then we just need to
258259 -- check it refers to a symbol in another module.
259260 (Nothing, Just mn'') -> do
260− modExports <- getExports env mn''
261− maybe (throwError . errorMessage $ unknown qname) return (getE modExports name)
261+ case M.lookup mn'' env of
262+ Nothing
263+ | mn'' `S.member` importedVirtualModules imports -> throwUnknown
264+ | otherwise -> throwError . errorMessage $ UnknownModule mn''
265+ Just env' -> maybe throwUnknown return (getE (envModuleExports env') name)
262266
263267 -- If neither of the above cases are true then it's an undefined or
264268 -- unimported symbol.
265− _ -> throwError . errorMessage $ unknown qname
269+ _ -> throwUnknown
266270
267271 where
268272 positioned err = case pos of
269273 Nothing -> err
270274 Just pos' -> rethrowWithPosition pos' err
275+ throwUnknown = throwError . errorMessage $ unknown qname
271276
272277-- |
273278-- Replaces `ProperRef` export values with a `TypeRef` or `TypeClassRef`
src/Language/PureScript/Sugar/Names/Env.hs+9−3
@@ -22,6 +22,7 @@ import Data.Function (on)
2222import Data.List (groupBy, sortBy, nub)
2323import Data.Maybe (fromJust)
2424import qualified Data.Map as M
25+import qualified Data.Set as S
2526
2627import Control.Monad
2728import Control.Monad.Error.Class (MonadError(..))
@@ -54,16 +55,21 @@ data Imports = Imports
5455 --
5556 , importedValues :: M.Map (Qualified Ident) [(Qualified Ident, ModuleName)]
5657 -- |
57− -- The list of modules that have been imported into the current scope.
58+ -- The modules that have been imported into the current scope.
5859 --
59− , importedModules :: [ModuleName]
60+ , importedModules :: S.Set ModuleName
61+ -- |
62+ -- The names of "virtual" modules that come into existence when "import as"
63+ -- is used.
64+ --
65+ , importedVirtualModules :: S.Set ModuleName
6066 } deriving (Show, Read)
6167
6268-- |
6369-- An empty 'Imports' value.
6470--
6571nullImports :: Imports
66−nullImports = Imports M.empty M.empty M.empty M.empty []
72+nullImports = Imports M.empty M.empty M.empty M.empty S.empty S.empty
6773
6874-- |
6975-- The exported declarations from a module.
src/Language/PureScript/Sugar/Names/Imports.hs+5−1
@@ -23,6 +23,7 @@ import Control.Monad.Error.Class (MonadError(..))
2323import Control.Monad.Writer (MonadWriter(..))
2424
2525import qualified Data.Map as M
26+import qualified Data.Set as S
2627
2728import Language.PureScript.Crash
2829import Language.PureScript.AST
@@ -168,7 +169,10 @@ resolveModuleImport env ie (mn, imps) = foldM go ie imps
168169 go :: Imports -> (Maybe SourceSpan, ImportDeclarationType, Maybe ModuleName) -> m Imports
169170 go ie' (pos, typ, impQual) = do
170171 modExports <- positioned $ maybe (throwError . errorMessage $ UnknownModule mn) (return . envModuleExports) $ mn `M.lookup` env
171− let ie'' = ie' { importedModules = mn : importedModules ie' }
172+ let virtualModules = importedVirtualModules ie'
173+ ie'' = ie' { importedModules = S.insert mn (importedModules ie')
174+ , importedVirtualModules = maybe virtualModules (`S.insert` virtualModules) impQual
175+ }
172176 positioned $ resolveImport mn modExports ie'' impQual typ
173177 where
174178 positioned err = case pos of