@@ -448,6 +448,7 @@ parseFileContents preprocessor filename (time, contents) = do
448448 Ex.throwE $ mkErrorDoc dflags locErr msgErr
449449#else
450450 PFailed s ->
451+ -- A fatal parse error was encountered.
451452 Ex.throwE $ toDiagnostics dflags $ snd $ getMessages s dflags
452453#endif
453454 POk pst rdr_module ->
@@ -455,9 +456,22 @@ parseFileContents preprocessor filename (time, contents) = do
455456 (Map.fromListWith (++) $ annotations pst,
456457 Map.fromList ((noSrcSpan,comment_q pst)
457458 :annotations_comments pst))
458− (warns,_) = getMessages pst dflags
459+ (warns, errs) = getMessages pst dflags
459460 in
460461 do
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
470+ -- be produced.
471+ unless (null errs) $
472+ Ex.throwE $ toDiagnostics dflags $ snd $ getMessages pst dflags
473+
474+ -- Ok, we got here. It's safe to continue.
461475 let (errs, parsed) = preprocessor rdr_module
462476 unless (null errs) $ Ex.throwE $ mkErrors dflags errs
463477 ms <- getModSummaryFromBuffer filename (contents, time) dflags parsed