mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 18:11:08 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user