mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 14:48:10 +00:00
Add support for default values for non-generic parameters of generic functions. (#8011)
A first step in expanding support for default values for parameters in generic functions. Adds code to parameter type deduction to include default values for absent call arguments. In support of that, this PR also generalizes a function from `export.cpp` that is useful to extract a default `ConstantId` value from an arbitrary function paramater pattern.
This commit is contained in:
1 parent
04f456dddd
commit
503f09037d
5 files changed
+604
-46
No files matched your search
@@ -360,4 +360,26 @@ auto PerformAction(Context& context, SemIR::LocId /*loc_id*/,
|
||||
}
|
||||
}
|
||||
|
||||
auto ExtractParameterDefault(Context& context,
|
||||
SemIR::InstId param_pattern_inst_id)
|
||||
-> SemIR::ConstantId {
|
||||
auto pattern_id =
|
||||
context.constant_values().GetConstantInstId(param_pattern_inst_id);
|
||||
while (pattern_id.has_value()) {
|
||||
CARBON_KIND_SWITCH(context.insts().Get(pattern_id)) {
|
||||
case CARBON_KIND(SemIR::DefaultValuePattern inst): {
|
||||
return context.constant_values().Get(inst.value_id);
|
||||
}
|
||||
case CARBON_KIND_ANY(SemIR::AnyBindingPattern, inst): {
|
||||
pattern_id = inst.subpattern_id;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return SemIR::ConstantId::None;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SemIR::ConstantId::None;
|
||||
}
|
||||
|
||||
} // namespace Carbon::Check
|
||||
Reference in new issue
Block a user