mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 22:02:51 +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:
@@ -959,12 +959,12 @@ auto MatchContext::DoPostWork(State state,
|
||||
.GetDefaultValues()[default_value_pattern.default_value_id.index];
|
||||
// If a constant was specified, we should be able to convert it into the
|
||||
// type of the parameter.
|
||||
if (default_value_inst_id != SemIR::InstId::None) {
|
||||
if (!context_.insts().Is<SemIR::UnspecifiedValue>(default_value_inst_id)) {
|
||||
// We should be able to convert the supplied constant into the type of
|
||||
// the parameter.
|
||||
auto converted_id = TryConvertToValueOfType(
|
||||
context_, context_.insts().GetCanonicalLocId(default_value_inst_id),
|
||||
default_value_inst_id, param_type_id);
|
||||
auto converted_id =
|
||||
TryConvertToValueOfType(context_, SemIR::LocId(default_value_inst_id),
|
||||
default_value_inst_id, param_type_id);
|
||||
if (converted_id == SemIR::ErrorInst::InstId) {
|
||||
CARBON_DIAGNOSTIC(
|
||||
PatternDefaultValueTypeMismatch, Error,
|
||||
@@ -974,11 +974,8 @@ auto MatchContext::DoPostWork(State state,
|
||||
// TODO: should be able to provide precise locations for both default
|
||||
// value expression and the type of the pattern, but we can't because
|
||||
// they are both constants.
|
||||
context_.emitter().Emit(
|
||||
LocIdForDiagnostics(
|
||||
context_.insts().GetCanonicalLocId(entry.pattern_id)),
|
||||
PatternDefaultValueTypeMismatch, default_value_inst_id,
|
||||
param_inst_id);
|
||||
context_.emitter().Emit(entry.pattern_id, PatternDefaultValueTypeMismatch,
|
||||
default_value_inst_id, param_inst_id);
|
||||
}
|
||||
}
|
||||
results_stack_.PopArray();
|
||||
|
||||
Reference in New Issue
Block a user