From 088f0c1e4fa991e6e494fa0e668456b36bcffea5 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 11 Mar 2018 12:44:12 +0000 Subject: [PATCH 1/3] Add source span for UnnecessaryFFIModule --- src/Language/PureScript/Ide/Rebuild.hs | 2 +- src/Language/PureScript/Make.hs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Language/PureScript/Ide/Rebuild.hs b/src/Language/PureScript/Ide/Rebuild.hs index c4f4b204a8..6604e2de33 100644 --- a/src/Language/PureScript/Ide/Rebuild.hs +++ b/src/Language/PureScript/Ide/Rebuild.hs @@ -158,7 +158,7 @@ shushProgress ma _ = -- files though) shushCodegen :: P.MakeActions P.Make -> MakeActionsEnv -> P.MakeActions P.Make shushCodegen ma MakeActionsEnv{..} = - ma { P.codegen = \_ _ _ -> pure () } + ma { P.codegen = \_ _ _ _ -> pure () } -- | Returns a topologically sorted list of dependent ExternsFiles for the given -- module. Throws an error if there is a cyclic dependency within the diff --git a/src/Language/PureScript/Make.hs b/src/Language/PureScript/Make.hs index 3031dc315c..c98305ec0d 100644 --- a/src/Language/PureScript/Make.hs +++ b/src/Language/PureScript/Make.hs @@ -108,7 +108,7 @@ data MakeActions m = MakeActions , readExterns :: ModuleName -> m (FilePath, Externs) -- ^ Read the externs file for a module as a string and also return the actual -- path for the file. - , codegen :: CF.Module CF.Ann -> Environment -> Externs -> SupplyT m () + , codegen :: SourceSpan -> CF.Module CF.Ann -> Environment -> Externs -> SupplyT m () -- ^ Run the code generator for the module and write any required output files. , progress :: ProgressMessage -> m () -- ^ Respond to a progress update. @@ -154,7 +154,7 @@ rebuildModule MakeActions{..} externs m@(Module _ _ moduleName _ _) = do corefn = CF.moduleToCoreFn env' mod' [renamed] = renameInModules [corefn] exts = moduleToExternsFile mod' env' - evalSupplyT nextVar' . codegen renamed env' . encode $ exts + evalSupplyT nextVar' . codegen ss renamed env' . encode $ exts return exts -- | Compiles in "make" mode, compiling each module separately to a @.js@ file and an @externs.json@ file. @@ -344,13 +344,13 @@ buildMakeActions outputDir filePathMap foreigns usePrefix = let path = outputDir T.unpack (runModuleName mn) "externs.json" (path, ) <$> readTextFile path - codegen :: CF.Module CF.Ann -> Environment -> Externs -> SupplyT Make () - codegen m _ exts = do + codegen :: SourceSpan -> CF.Module CF.Ann -> Environment -> Externs -> SupplyT Make () + codegen modSS m _ exts = do let mn = CF.moduleName m foreignInclude <- case mn `M.lookup` foreigns of Just path | not $ requiresForeign m -> do - tell $ errorMessage $ UnnecessaryFFIModule mn path + tell $ errorMessage' modSS $ UnnecessaryFFIModule mn path return Nothing | otherwise -> do checkForeignDecls m path From 8197e5f3025497b1e0d016bf8e3348ec8da97782 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 11 Mar 2018 12:46:27 +0000 Subject: [PATCH 2/3] Add source spans for more FFI warnings --- src/Language/PureScript/Make.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Language/PureScript/Make.hs b/src/Language/PureScript/Make.hs index c98305ec0d..12e68ec315 100644 --- a/src/Language/PureScript/Make.hs +++ b/src/Language/PureScript/Make.hs @@ -353,7 +353,7 @@ buildMakeActions outputDir filePathMap foreigns usePrefix = tell $ errorMessage' modSS $ UnnecessaryFFIModule mn path return Nothing | otherwise -> do - checkForeignDecls m path + checkForeignDecls modSS m path return $ Just $ Imp.App Nothing (Imp.Var Nothing "require") [Imp.StringLiteral Nothing "./foreign"] Nothing | requiresForeign m -> throwError . errorMessage $ MissingFFIModule mn | otherwise -> return Nothing @@ -425,8 +425,8 @@ buildMakeActions outputDir filePathMap foreigns usePrefix = -- | Check that the declarations in a given PureScript module match with those -- in its corresponding foreign module. -checkForeignDecls :: CF.Module ann -> FilePath -> SupplyT Make () -checkForeignDecls m path = do +checkForeignDecls :: SourceSpan -> CF.Module ann -> FilePath -> SupplyT Make () +checkForeignDecls modSS m path = do jsStr <- lift $ readTextFile path js <- either (errorParsingModule . Bundle.UnableToParseModule) pure $ JS.parse (BU8.toString (B.toStrict jsStr)) path @@ -439,12 +439,12 @@ checkForeignDecls m path = do let unusedFFI = foreignIdents S.\\ importedIdents unless (null unusedFFI) $ - tell . errorMessage . UnusedFFIImplementations mname $ + tell . errorMessage' modSS . UnusedFFIImplementations mname $ S.toList unusedFFI let missingFFI = importedIdents S.\\ foreignIdents unless (null missingFFI) $ - throwError . errorMessage . MissingFFIImplementations mname $ + throwError . errorMessage' modSS . MissingFFIImplementations mname $ S.toList missingFFI where From 7187e4d9a1f6343de07e974f9575aaf6db5d35c7 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 11 Mar 2018 12:54:15 +0000 Subject: [PATCH 3/3] Add error test for MissingFFIImplementations --- examples/failing/MissingFFIImplementations.js | 1 + examples/failing/MissingFFIImplementations.purs | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 examples/failing/MissingFFIImplementations.js create mode 100644 examples/failing/MissingFFIImplementations.purs diff --git a/examples/failing/MissingFFIImplementations.js b/examples/failing/MissingFFIImplementations.js new file mode 100644 index 0000000000..d29ee4cff9 --- /dev/null +++ b/examples/failing/MissingFFIImplementations.js @@ -0,0 +1 @@ +exports.yes = true; diff --git a/examples/failing/MissingFFIImplementations.purs b/examples/failing/MissingFFIImplementations.purs new file mode 100644 index 0000000000..1f47ef841b --- /dev/null +++ b/examples/failing/MissingFFIImplementations.purs @@ -0,0 +1,5 @@ +-- @shouldFailWith MissingFFIImplementations +module Main where + +foreign import yes :: Boolean +foreign import no :: Boolean