Commit 7402994c authored by Simon Marlow's avatar Simon Marlow
Browse files

FIX #1677; poor error message for misspelled module declaration

parent a9aeb7fa
......@@ -656,7 +656,7 @@ runPhase (Hsc src_flavour) stop dflags0 basename suff input_fn get_output_fn _ma
; return (Nothing, mkModuleName m, [], []) }
other -> do { buf <- hGetStringBuffer input_fn
; (src_imps,imps,L _ mod_name) <- getImports dflags buf input_fn
; (src_imps,imps,L _ mod_name) <- getImports dflags buf input_fn (basename `joinFileExt` suff)
; return (Just buf, mod_name, imps, src_imps) }
-- Build a ModLocation to pass to hscMain.
......
......@@ -1635,7 +1635,7 @@ summariseFile hsc_env old_summaries file mb_phase maybe_buf
(dflags', hspp_fn, buf)
<- preprocessFile dflags file mb_phase maybe_buf
(srcimps,the_imps, L _ mod_name) <- getImports dflags' buf hspp_fn
(srcimps,the_imps, L _ mod_name) <- getImports dflags' buf hspp_fn file
-- Make a ModLocation for this file
location <- mkHomeModLocation dflags mod_name file
......@@ -1755,7 +1755,7 @@ summariseModule hsc_env old_summary_map is_boot (L loc wanted_mod) maybe_buf exc
-- Preprocess the source file and get its imports
-- The dflags' contains the OPTIONS pragmas
(dflags', hspp_fn, buf) <- preprocessFile dflags src_fn Nothing maybe_buf
(srcimps, the_imps, L mod_loc mod_name) <- getImports dflags' buf hspp_fn
(srcimps, the_imps, L mod_loc mod_name) <- getImports dflags' buf hspp_fn src_fn
when (mod_name /= wanted_mod) $
throwDyn $ mkPlainErrMsg mod_loc $
......
......@@ -15,7 +15,7 @@
-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
-- for details
module HeaderInfo ( getImportsFromFile, getImports
module HeaderInfo ( getImports
, getOptionsFromFile, getOptions
, optionsErrorMsgs ) where
......@@ -56,18 +56,9 @@ import IOExts ( openFileEx, IOModeEx(..) )
openBinaryFile fp mode = openFileEx fp (BinaryMode mode)
#endif
-- getImportsFromFile is careful to close the file afterwards, otherwise
-- we can end up with a large number of open handles before the garbage
-- collector gets around to closing them.
getImportsFromFile :: DynFlags -> FilePath
-> IO ([Located ModuleName], [Located ModuleName], Located ModuleName)
getImportsFromFile dflags filename = do
buf <- hGetStringBuffer filename
getImports dflags buf filename
getImports :: DynFlags -> StringBuffer -> FilePath
getImports :: DynFlags -> StringBuffer -> FilePath -> FilePath
-> IO ([Located ModuleName], [Located ModuleName], Located ModuleName)
getImports dflags buf filename = do
getImports dflags buf filename source_filename = do
let loc = mkSrcLoc (mkFastString filename) 1 0
case unP parseHeader (mkPState buf loc dflags) of
PFailed span err -> parseError span err
......@@ -78,7 +69,8 @@ getImports dflags buf filename = do
case rdr_module of
L _ (HsModule mb_mod _ imps _ _ _ _ _) ->
let
mod = mb_mod `orElse` L (srcLocSpan loc) mAIN_NAME
main_loc = mkSrcLoc (mkFastString source_filename) 1 0
mod = mb_mod `orElse` L (srcLocSpan main_loc) mAIN_NAME
(src_idecls, ord_idecls) = partition isSourceIdecl (map unLoc imps)
source_imps = map getImpMod src_idecls
ordinary_imps = filter ((/= moduleName gHC_PRIM) . unLoc)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment