mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user