mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Reverse nesting structure of parameter patterns (#6930)
See [here](https://docs.google.com/document/d/1rWcueFwIfZox6GKVGxiUG4cBzjrZ6djXiIDGyJDtrE4/edit?tab=t.0#heading=h.7mi143mdhr2h) for an overview of the changes and their rationale. Assisted-by: Gemini 3.1 Pro via Antigravity
This commit is contained in:
@@ -312,20 +312,28 @@ static auto IsValidEntryPointParamList(Context& context, Parse::NodeId node_id,
|
||||
continue;
|
||||
}
|
||||
|
||||
auto param =
|
||||
context.insts().TryGetAs<SemIR::ValueParamPattern>(param_pattern_id);
|
||||
if (!param) {
|
||||
// Only value parameters are supported for now.
|
||||
// Validate that this is a by-value parameter, which is represented as an
|
||||
// WrapperBindingPattern wrapping a ValueParamPattern.
|
||||
auto type_id = SemIR::TypeId::None;
|
||||
if (auto binding = context.insts().TryGetAs<SemIR::WrapperBindingPattern>(
|
||||
param_pattern_id)) {
|
||||
if (auto param_pattern =
|
||||
context.insts().TryGetAs<SemIR::ValueParamPattern>(
|
||||
binding->subpattern_id)) {
|
||||
type_id = param_pattern->type_id;
|
||||
}
|
||||
}
|
||||
if (!type_id.has_value()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (param->type_id == SemIR::ErrorInst::TypeId) {
|
||||
if (type_id == SemIR::ErrorInst::TypeId) {
|
||||
// Ignore parameters with erroneous types.
|
||||
continue;
|
||||
}
|
||||
|
||||
auto param_type_inst_id = context.types()
|
||||
.GetAs<SemIR::PatternType>(param->type_id)
|
||||
.GetAs<SemIR::PatternType>(type_id)
|
||||
.scrutinee_type_inst_id;
|
||||
switch (index) {
|
||||
case 0: {
|
||||
@@ -614,8 +622,7 @@ static auto CheckUnusedBindingsInPattern(Context& context,
|
||||
auto current_id = work_list.pop_back_val();
|
||||
auto inst = context.insts().Get(current_id);
|
||||
CARBON_KIND_SWITCH(inst) {
|
||||
case CARBON_KIND_ANY(SemIR::AnyParamPattern, param): {
|
||||
work_list.push_back(param.subpattern_id);
|
||||
case CARBON_KIND_ANY(SemIR::AnyLeafParamPattern, _): {
|
||||
break;
|
||||
}
|
||||
case CARBON_KIND_ANY(SemIR::AnyBindingPattern, bind): {
|
||||
@@ -628,9 +635,12 @@ static auto CheckUnusedBindingsInPattern(Context& context,
|
||||
"`unused` modifier on declaration");
|
||||
context.emitter().Emit(current_id, UnusedModifierOnDeclaration);
|
||||
}
|
||||
if (bind.kind == SemIR::WrapperBindingPattern::Kind) {
|
||||
work_list.push_back(bind.subpattern_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CARBON_KIND(SemIR::VarPattern var_pattern): {
|
||||
case CARBON_KIND_ANY(SemIR::AnyVarPattern, var_pattern): {
|
||||
work_list.push_back(var_pattern.subpattern_id);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user