Factor out common pattern of trying to complete a type then falling back to an error type if that fails. (#3454)

As requested in [review of
#3450](https://github.com/carbon-language/carbon-lang/pull/3450#discussion_r1414220143).
This commit is contained in:
Richard Smith
2023-12-07 01:53:30 +00:00
committed by GitHub
parent fe6f7b4330
commit 18d7ba9542
4 changed files with 48 additions and 45 deletions
+7 -9
View File
@@ -214,15 +214,13 @@ auto HandleBaseDecl(Context& context, Parse::NodeId parse_node) -> bool {
}
auto base_type_id = ExprAsType(context, parse_node, base_type_expr_id);
if (!context.TryToCompleteType(base_type_id, [&] {
CARBON_DIAGNOSTIC(IncompleteTypeInBaseDecl, Error,
"Base `{0}` is an incomplete type.", std::string);
return context.emitter().Build(
parse_node, IncompleteTypeInBaseDecl,
context.sem_ir().StringifyType(base_type_id));
})) {
base_type_id = SemIR::TypeId::Error;
}
base_type_id = context.AsCompleteType(base_type_id, [&] {
CARBON_DIAGNOSTIC(IncompleteTypeInBaseDecl, Error,
"Base `{0}` is an incomplete type.", std::string);
return context.emitter().Build(
parse_node, IncompleteTypeInBaseDecl,
context.sem_ir().StringifyType(base_type_id));
});
if (base_type_id != SemIR::TypeId::Error) {
// For now, we treat all types that aren't introduced by a `class`