Skip to content

Commit 80c671e

Browse files
authored
Error positions for FFI related errors (purescript#3276)
* Add source span for UnnecessaryFFIModule * Add source spans for more FFI warnings * Add error test for MissingFFIImplementations
1 parent 3171a77 commit 80c671e

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.yes = true;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- @shouldFailWith MissingFFIImplementations
2+
module Main where
3+
4+
foreign import yes :: Boolean
5+
foreign import no :: Boolean

src/Language/PureScript/Ide/Rebuild.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ shushProgress ma _ =
158158
-- files though)
159159
shushCodegen :: P.MakeActions P.Make -> MakeActionsEnv -> P.MakeActions P.Make
160160
shushCodegen ma MakeActionsEnv{..} =
161-
ma { P.codegen = \_ _ _ -> pure () }
161+
ma { P.codegen = \_ _ _ _ -> pure () }
162162

163163
-- | Returns a topologically sorted list of dependent ExternsFiles for the given
164164
-- module. Throws an error if there is a cyclic dependency within the

src/Language/PureScript/Make.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ data MakeActions m = MakeActions
108108
, readExterns :: ModuleName -> m (FilePath, Externs)
109109
-- ^ Read the externs file for a module as a string and also return the actual
110110
-- path for the file.
111-
, codegen :: CF.Module CF.Ann -> Environment -> Externs -> SupplyT m ()
111+
, codegen :: SourceSpan -> CF.Module CF.Ann -> Environment -> Externs -> SupplyT m ()
112112
-- ^ Run the code generator for the module and write any required output files.
113113
, progress :: ProgressMessage -> m ()
114114
-- ^ Respond to a progress update.
@@ -154,7 +154,7 @@ rebuildModule MakeActions{..} externs m@(Module _ _ moduleName _ _) = do
154154
corefn = CF.moduleToCoreFn env' mod'
155155
[renamed] = renameInModules [corefn]
156156
exts = moduleToExternsFile mod' env'
157-
evalSupplyT nextVar' . codegen renamed env' . encode $ exts
157+
evalSupplyT nextVar' . codegen ss renamed env' . encode $ exts
158158
return exts
159159

160160
-- | Compiles in "make" mode, compiling each module separately to a @.js@ file and an @externs.json@ file.
@@ -344,16 +344,16 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
344344
let path = outputDir </> T.unpack (runModuleName mn) </> "externs.json"
345345
(path, ) <$> readTextFile path
346346

347-
codegen :: CF.Module CF.Ann -> Environment -> Externs -> SupplyT Make ()
348-
codegen m _ exts = do
347+
codegen :: SourceSpan -> CF.Module CF.Ann -> Environment -> Externs -> SupplyT Make ()
348+
codegen modSS m _ exts = do
349349
let mn = CF.moduleName m
350350
foreignInclude <- case mn `M.lookup` foreigns of
351351
Just path
352352
| not $ requiresForeign m -> do
353-
tell $ errorMessage $ UnnecessaryFFIModule mn path
353+
tell $ errorMessage' modSS $ UnnecessaryFFIModule mn path
354354
return Nothing
355355
| otherwise -> do
356-
checkForeignDecls m path
356+
checkForeignDecls modSS m path
357357
return $ Just $ Imp.App Nothing (Imp.Var Nothing "require") [Imp.StringLiteral Nothing "./foreign"]
358358
Nothing | requiresForeign m -> throwError . errorMessage $ MissingFFIModule mn
359359
| otherwise -> return Nothing
@@ -425,8 +425,8 @@ buildMakeActions outputDir filePathMap foreigns usePrefix =
425425

426426
-- | Check that the declarations in a given PureScript module match with those
427427
-- in its corresponding foreign module.
428-
checkForeignDecls :: CF.Module ann -> FilePath -> SupplyT Make ()
429-
checkForeignDecls m path = do
428+
checkForeignDecls :: SourceSpan -> CF.Module ann -> FilePath -> SupplyT Make ()
429+
checkForeignDecls modSS m path = do
430430
jsStr <- lift $ readTextFile path
431431
js <- either (errorParsingModule . Bundle.UnableToParseModule) pure $ JS.parse (BU8.toString (B.toStrict jsStr)) path
432432

@@ -439,12 +439,12 @@ checkForeignDecls m path = do
439439

440440
let unusedFFI = foreignIdents S.\\ importedIdents
441441
unless (null unusedFFI) $
442-
tell . errorMessage . UnusedFFIImplementations mname $
442+
tell . errorMessage' modSS . UnusedFFIImplementations mname $
443443
S.toList unusedFFI
444444

445445
let missingFFI = importedIdents S.\\ foreignIdents
446446
unless (null missingFFI) $
447-
throwError . errorMessage . MissingFFIImplementations mname $
447+
throwError . errorMessage' modSS . MissingFFIImplementations mname $
448448
S.toList missingFFI
449449

450450
where

0 commit comments

Comments
 (0)