From: Simon Marlow Date: Tue, 11 Sep 2007 08:54:52 +0000 (+0000) Subject: FIX #1677; poor error message for misspelled module declaration X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=7402994c4abb6a698280dd3dacb0867c7e1388e1 FIX #1677; poor error message for misspelled module declaration --- diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs index c0ea4fc..19e3a6a 100644 --- a/compiler/main/DriverPipeline.hs +++ b/compiler/main/DriverPipeline.hs @@ -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. diff --git a/compiler/main/GHC.hs b/compiler/main/GHC.hs index 846bec1..30005ed 100644 --- a/compiler/main/GHC.hs +++ b/compiler/main/GHC.hs @@ -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 $ diff --git a/compiler/main/HeaderInfo.hs b/compiler/main/HeaderInfo.hs index 90c6155..ee2cde8 100644 --- a/compiler/main/HeaderInfo.hs +++ b/compiler/main/HeaderInfo.hs @@ -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)