Reconcile function default values between decl and def (#7665)

Updates the pattern matching code to support unspecified default values.
Adds logic to decl and def merge code to diagnose mismatches in defaults
if specified in both places, or if let entirely unspecified.

Per https://github.com/carbon-language/carbon-lang/pull/7521.
This commit is contained in:
Lucile Rose Nihlen
2026-09-08 20:41:58 +00:00
committed by GitHub
parent 5a07a14fe9
commit ca9e985fa8
30 changed files with 4624 additions and 3875 deletions
+19 -15
View File
@@ -597,24 +597,28 @@ auto Formatter::FormatFunction(FunctionId id, const Function& fn) -> void {
out() << "]";
}
if (fn.call_param_default_values_id.has_value()) {
out() << " default_values:";
// The default values are encoded as instructions referring to constants,
// and as such have no location, and so are normally elided when
// use_dump_sem_ir_ranges_ is true. However, if the function containing
// these default values is to be printed, it should also include these
// defaults, so we temporarily disable this flag to force the printing of
// the contents of this block.
auto format_mask = use_dump_sem_ir_ranges_;
use_dump_sem_ir_ranges_ = false;
FormatTrailingBlock(fn.call_param_default_values_id);
use_dump_sem_ir_ranges_ = format_mask;
}
if (!fn.body_block_ids.empty()) {
if (!fn.body_block_ids.empty() ||
fn.call_param_default_values_id.has_value()) {
out() << ' ';
OpenBrace();
if (fn.call_param_default_values_id.has_value()) {
IndentLabel();
out() << "!default_values:\n";
// The default values are encoded as canonical instructions,
// and as such have no location, and so are normally elided when
// use_dump_sem_ir_ranges_ is true. However, if the function containing
// these default values is to be printed, it should also include these
// defaults, so we temporarily disable this flag to force the printing of
// the contents of this block.
// TODO: drop this code once default values are stored as non-canonical
// instructions.
auto format_mask = use_dump_sem_ir_ranges_;
use_dump_sem_ir_ranges_ = false;
FormatCodeBlock(fn.call_param_default_values_id);
use_dump_sem_ir_ranges_ = format_mask;
}
for (auto block_id : fn.body_block_ids) {
IndentLabel();
FormatLabel(block_id);