@@ -22,6 +22,7 @@ namespace {
2222
2323std::string FormatError (const Error& error,
2424 Location::Type location_type,
25+ const std::string_view filename,
2526 const Color& color,
2627 LexerSourceLineFinder* line_finder,
2728 int source_line_max_length,
@@ -32,8 +33,9 @@ std::string FormatError(const Error& error,
3233 result += color.MaybeBoldCode ();
3334
3435 const Location& loc = error.loc ;
35- if (!loc.filename .empty ()) {
36- result += loc.filename ;
36+ if ((location_type != Location::Type::Binary || loc.print_filename ) &&
37+ !filename.empty ()) {
38+ result += filename;
3739 result += " :" ;
3840 }
3941
@@ -84,6 +86,7 @@ std::string FormatError(const Error& error,
8486
8587std::string FormatErrorsToString (const Errors& errors,
8688 Location::Type location_type,
89+ const std::string_view filename,
8790 LexerSourceLineFinder* line_finder,
8891 const Color& color,
8992 const std::string& header,
@@ -107,23 +110,24 @@ std::string FormatErrorsToString(const Errors& errors,
107110
108111 int indent = header.empty () ? 0 : 2 ;
109112
110- result += FormatError (error, location_type, color, line_finder,
113+ result += FormatError (error, location_type, filename, color, line_finder,
111114 source_line_max_length, indent);
112115 }
113116 return result;
114117}
115118
116119void FormatErrorsToFile (const Errors& errors,
117120 Location::Type location_type,
121+ const std::string_view filename,
118122 LexerSourceLineFinder* line_finder,
119123 FILE* file,
120124 const std::string& header,
121125 PrintHeader print_header,
122126 int source_line_max_length) {
123127 Color color (file);
124128 std::string s =
125- FormatErrorsToString (errors, location_type, line_finder, color, header ,
126- print_header, source_line_max_length);
129+ FormatErrorsToString (errors, location_type, filename, line_finder, color ,
130+ header, print_header, source_line_max_length);
127131 fwrite (s.data (), 1 , s.size (), file);
128132}
129133
0 commit comments