mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Allow impl redecl in match_first after a definition (#7491)
Previously the last decl had to be the definition. Now we allow a declaration after a definition, so that the user can write a match_first block last, and put (re-)declarations of impls in it, after the definitions have already been written elsewhere. We track the location of the decl that was associated with a match_first block so that we can correctly point to it in diagnostics when an impl is written twice in match_first blocks. Since impls may not be redeclared across an import boundary, we will never have a `SemIR::Impl` with a match_first from a different file in a redeclaration, so we don't need to import the location of a previous decl that was in a match_first for diagnostics. As such we just store a LocId on the `SemIR::Impl` struct.
This commit is contained in:
@@ -518,6 +518,15 @@ auto Formatter::FormatImpl(ImplId id, const Impl& impl_info) -> void {
|
||||
FormatNameScope(impl_info.scope_id);
|
||||
}
|
||||
|
||||
if (impl_info.match_first_id.has_value()) {
|
||||
Indent();
|
||||
out() << "match_first = position " << impl_info.match_first_position;
|
||||
if (impl_info.match_first_is_final) {
|
||||
out() << ", final";
|
||||
}
|
||||
out() << "\n";
|
||||
}
|
||||
|
||||
Indent();
|
||||
out() << "witness = ";
|
||||
FormatArg(impl_info.witness_id);
|
||||
|
||||
Reference in New Issue
Block a user