Implement syntactic merge checks for parameters. (#4149)

Note this isn't implementing checking through imports. The parse node
there is harder to access through the context, so would require
examining the entity in order to get the import declaration, to get at
the ImportIR. We also don't have a parse tree attached in that case, and
would need to add one to SemIR::File. But I believe we do want to add
that, so it's explicitly a TODO.

Note GetTokenText re-lexes literal values, so there's a bit of potential
overhead there. Not sure if we want a more efficient manner for
comparing in cases like this.
This commit is contained in:
Jon Ross-Perkins
2024-07-23 20:32:24 +00:00
committed by GitHub
parent 07c286e3cb
commit db022658c6
26 changed files with 2738 additions and 26 deletions
+8 -6
View File
@@ -366,8 +366,9 @@ auto DeclNameStack::ResolveAsScope(const NameContext& name_context,
return InvalidResult;
}
auto new_params =
DeclParams(name.name_loc_id, name.implicit_params_id, name.params_id);
auto new_params = DeclParams(name.name_loc_id, name.first_param_node_id,
name.last_param_node_id, name.implicit_params_id,
name.params_id);
// Find the scope corresponding to the resolved instruction.
CARBON_KIND_SWITCH(context_->insts().Get(name_context.resolved_inst_id)) {
@@ -404,10 +405,11 @@ auto DeclNameStack::ResolveAsScope(const NameContext& name_context,
case CARBON_KIND(SemIR::Namespace resolved_inst): {
auto scope_id = resolved_inst.name_scope_id;
auto& scope = context_->name_scopes().Get(scope_id);
if (!CheckRedeclParamsMatch(*context_, new_params,
DeclParams(name_context.resolved_inst_id,
SemIR::InstBlockId::Invalid,
SemIR::InstBlockId::Invalid))) {
if (!CheckRedeclParamsMatch(
*context_, new_params,
DeclParams(name_context.resolved_inst_id, Parse::NodeId::Invalid,
Parse::NodeId::Invalid, SemIR::InstBlockId::Invalid,
SemIR::InstBlockId::Invalid))) {
return InvalidResult;
}
if (scope.is_closed_import) {