mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 09:15:49 +01:00
Add a DiagnosticBuilder to support context on diagnostics. (#2490)
This is currently used once for PreviousDefinition in semantics. This PR doesn't just add a builder, it also adds support to the emitter itself to collect notes attached to a diagnostic, and to the consumers and emitters to print all of them. Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
co-authored by
Chandler Carruth
parent
149107965c
commit
6c9b7cba55
@@ -108,15 +108,13 @@ auto SemanticsParseTreeHandler::BindName(ParseTree::Node name_node,
|
||||
} else {
|
||||
CARBON_DIAGNOSTIC(NameRedefined, Error, "Redefining {0} in the same scope.",
|
||||
llvm::StringRef);
|
||||
emitter_->Emit(name_node, NameRedefined, name_str);
|
||||
|
||||
// TODO: This should be a note and sorted with the above diagnostic.
|
||||
// But that depends on more diagnostic support we currently don't have.
|
||||
CARBON_DIAGNOSTIC(PreviousDefinition, Note, "Previous definition is here.");
|
||||
auto prev_def_id = name_lookup_[name_id].back();
|
||||
auto prev_def = semantics_->GetNode(prev_def_id);
|
||||
CARBON_DIAGNOSTIC(PreviousDefinition, Error,
|
||||
"Previous definition is here.");
|
||||
emitter_->Emit(prev_def.parse_node(), PreviousDefinition);
|
||||
|
||||
emitter_->Build(name_node, NameRedefined, name_str)
|
||||
.Note(prev_def.parse_node(), PreviousDefinition)
|
||||
.Emit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user