mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Add diagnostics for extend impl misuse. (#3721)
To make the implementation simpler, make `PopWithParseNodeIf` return `pair<NodeId, optional<value>>` rather than `optional<pair<NodeId, value>>`. While wrapping the whole result in `optional` seems more principled, it's significantly harder to work with.
This commit is contained in:
@@ -70,26 +70,25 @@ static auto BuildFunctionDecl(Context& context,
|
||||
|
||||
auto return_type_id = SemIR::TypeId::Invalid;
|
||||
auto return_slot_id = SemIR::InstId::Invalid;
|
||||
if (auto return_node_and_id =
|
||||
if (auto [return_node, return_storage_id] =
|
||||
context.node_stack()
|
||||
.PopWithParseNodeIf<Parse::NodeKind::ReturnType>()) {
|
||||
auto return_storage_id = return_node_and_id->second;
|
||||
return_type_id = context.insts().Get(return_storage_id).type_id();
|
||||
.PopWithParseNodeIf<Parse::NodeKind::ReturnType>();
|
||||
return_storage_id) {
|
||||
return_type_id = context.insts().Get(*return_storage_id).type_id();
|
||||
|
||||
return_type_id = context.AsCompleteType(return_type_id, [&] {
|
||||
CARBON_DIAGNOSTIC(IncompleteTypeInFunctionReturnType, Error,
|
||||
"Function returns incomplete type `{0}`.",
|
||||
SemIR::TypeId);
|
||||
return context.emitter().Build(return_node_and_id->first,
|
||||
IncompleteTypeInFunctionReturnType,
|
||||
return_type_id);
|
||||
return context.emitter().Build(
|
||||
return_node, IncompleteTypeInFunctionReturnType, return_type_id);
|
||||
});
|
||||
|
||||
if (!SemIR::GetInitRepr(context.sem_ir(), return_type_id)
|
||||
.has_return_slot()) {
|
||||
// The function only has a return slot if it uses in-place initialization.
|
||||
} else {
|
||||
return_slot_id = return_storage_id;
|
||||
return_slot_id = *return_storage_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user