@@ -448,6 +448,7 @@ parseFileContents preprocessor filename (time, contents) = do
448 Ex.throwE $ mkErrorDoc dflags locErr msgErr
448 Ex.throwE $ mkErrorDoc dflags locErr msgErr
450 PFailed s ->
450 PFailed s ->
451+ -- A fatal parse error was encountered.
451 Ex.throwE $ toDiagnostics dflags $ snd $ getMessages s dflags
452 Ex.throwE $ toDiagnostics dflags $ snd $ getMessages s dflags
453 POk pst rdr_module ->
454 POk pst rdr_module ->
@@ -455,9 +456,22 @@ parseFileContents preprocessor filename (time, contents) = do
455 (Map.fromListWith (++) $ annotations pst,
456 (Map.fromListWith (++) $ annotations pst,
456 Map.fromList ((noSrcSpan,comment_q pst)
457 Map.fromList ((noSrcSpan,comment_q pst)
457 :annotations_comments pst))
458 :annotations_comments pst))
458− (warns,_) = getMessages pst dflags
459+ (warns, errs) = getMessages pst dflags
462+ -- Just because we got a `POk`, it doesn't mean there
463+ -- weren't errors! To clarify, the GHC parser
464+ -- distinguishes between fatal and non-fatal
465+ -- errors. Non-fatal errors are the sort that don't
466+ -- prevent parsing from continuing (that is, a parse
467+ -- tree can still be produced despite the error so that
468+ -- further errors/warnings can be collected). Fatal
469+ -- errors are those from which a parse tree just can't
471+ unless (null errs) $
472+ Ex.throwE $ toDiagnostics dflags $ snd $ getMessages pst dflags
474+ -- Ok, we got here. It's safe to continue.
461 let (errs, parsed) = preprocessor rdr_module
475 let (errs, parsed) = preprocessor rdr_module
462 unless (null errs) $ Ex.throwE $ mkErrors dflags errs
476 unless (null errs) $ Ex.throwE $ mkErrors dflags errs
463 ms <- getModSummaryFromBuffer filename (contents, time) dflags parsed
477 ms <- getModSummaryFromBuffer filename (contents, time) dflags parsed