mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:11:27 +01:00
Fix a duplicate diagnostic on incomplete return types. (#6684)
For example, see toolchain/check/testdata/class/fail_incomplete.carbon for the diagnostic changes. `IncompleteTypeInFunctionReturnType` should remain, while the redundant `IncompleteTypeInFunctionParam` is removed. Note I'm deliberately trying to validate the return type after other parameters, because I think that's the better user experience. This does also incrementally change IR.
This commit is contained in:
@@ -310,11 +310,11 @@ auto CheckFunctionDefinitionSignature(Context& context,
|
||||
auto params_to_complete =
|
||||
context.inst_blocks().GetOrEmpty(function.call_params_id);
|
||||
|
||||
// Check the return type is complete.
|
||||
for (auto return_pattern_id :
|
||||
context.inst_blocks().GetOrEmpty(function.return_patterns_id)) {
|
||||
CheckFunctionReturnPatternType(context, SemIR::LocId(return_pattern_id),
|
||||
return_pattern_id, SemIR::SpecificId::None);
|
||||
// The return parameter will be diagnosed after and differently from other
|
||||
// parameters.
|
||||
auto return_call_param = SemIR::InstId::None;
|
||||
if (!params_to_complete.empty() && function.return_patterns_id.has_value()) {
|
||||
return_call_param = params_to_complete.consume_back();
|
||||
}
|
||||
|
||||
// Check the parameter types are complete.
|
||||
@@ -335,6 +335,25 @@ auto CheckFunctionDefinitionSignature(Context& context,
|
||||
param_ref_id, IncompleteTypeInFunctionParam, param_ref_id);
|
||||
});
|
||||
}
|
||||
|
||||
// Check the return type is complete.
|
||||
if (function.return_patterns_id.has_value()) {
|
||||
for (auto return_pattern_id :
|
||||
context.inst_blocks().Get(function.return_patterns_id)) {
|
||||
CheckFunctionReturnPatternType(context, SemIR::LocId(return_pattern_id),
|
||||
return_pattern_id,
|
||||
SemIR::SpecificId::None);
|
||||
}
|
||||
|
||||
// `CheckFunctionReturnPatternType` should have diagnosed incomplete types,
|
||||
// so don't `RequireCompleteType` on the return type.
|
||||
if (return_call_param.has_value()) {
|
||||
TryToCompleteType(
|
||||
context,
|
||||
context.insts().GetAs<SemIR::AnyParam>(return_call_param).type_id,
|
||||
SemIR::LocId(return_call_param));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Carbon::Check
|
||||
|
||||
Reference in New Issue
Block a user