mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 10:35:53 +01:00
Error: track message and prefix/location separately. (#1529)
This allows us to combine multiple Errors together without repeating the prefix information. Also fixes several cases where two "COMPILATION ERROR" prefixes would be prepended to the same message when errors with prefixes and locations were produced by the lexer and parser.
This commit is contained in:
@@ -29,10 +29,11 @@ static auto ParseImpl(yyscan_t scanner, Nonnull<Arena*> arena,
|
||||
}
|
||||
|
||||
if (auto syntax_error_code = parser(); syntax_error_code != 0) {
|
||||
const std::string error_message = context.error_messages().empty()
|
||||
? "Unknown parser error"
|
||||
: context.error_messages()[0];
|
||||
return Error(error_message);
|
||||
auto errors = context.take_errors();
|
||||
if (errors.empty()) {
|
||||
return Error("Unknown parser erroor");
|
||||
}
|
||||
return std::move(errors.front());
|
||||
}
|
||||
|
||||
// Return parse results.
|
||||
|
||||
Reference in New Issue
Block a user