Parsing and basic checking for abstract class and base class. (#3385)

For now, we require the same introducer to be used each time a class is
declared, but see #3384.

---------

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
Richard Smith
2023-11-13 20:38:21 +00:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 49591d1360
commit 2715e2276e
23 changed files with 520 additions and 114 deletions
+12 -1
View File
@@ -539,9 +539,20 @@ static auto ConvertStructToClass(Context& context, SemIR::StructType src_type,
SemIR::InstId value_id,
ConversionTarget target) -> SemIR::InstId {
PendingBlock target_block(context);
auto& class_info = context.classes().Get(dest_type.class_id);
if (class_info.inheritance_kind == SemIR::Class::Abstract) {
CARBON_DIAGNOSTIC(ConstructionOfAbstractClass, Error,
"Cannot construct instance of abstract class. "
"Consider using `partial {0}` instead.",
std::string);
context.emitter().Emit(context.insts().Get(value_id).parse_node(),
ConstructionOfAbstractClass,
context.sem_ir().StringifyType(target.type_id));
return SemIR::InstId::BuiltinError;
}
auto dest_struct_type = context.insts().GetAs<SemIR::StructType>(
context.sem_ir().GetTypeAllowBuiltinTypes(
context.classes().Get(dest_type.class_id).object_representation_id));
class_info.object_representation_id));
// If we're trying to create a class value, form a temporary for the value to
// point to.