Disallow creating instances of abstract classes (#4381)

A good first-pass, at least. (abstract adapters are rejected with this
change, though pending further language design discussion)

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
David Blaikie
2024-10-12 15:17:42 +00:00
committed by GitHub
co-authored by Richard Smith
parent bafddd8711
commit d491387a98
15 changed files with 870 additions and 145 deletions
+8 -1
View File
@@ -81,11 +81,18 @@ auto CheckFunctionReturnType(Context& context, SemIRLoc loc,
return context.emitter().Build(loc, IncompleteTypeInFunctionReturnType,
return_info.type_id);
};
auto diagnose_abstract_return_type = [&] {
CARBON_DIAGNOSTIC(AbstractTypeInFunctionReturnType, Error,
"function returns abstract type {0}", SemIR::TypeId);
return context.emitter().Build(loc, AbstractTypeInFunctionReturnType,
return_info.type_id);
};
// TODO: Consider suppressing the diagnostic if we've already diagnosed a
// definition or call to this function.
if (context.TryToCompleteType(return_info.type_id,
diagnose_incomplete_return_type)) {
diagnose_incomplete_return_type,
diagnose_abstract_return_type)) {
return_info = SemIR::ReturnTypeInfo::ForFunction(context.sem_ir(),
function, specific_id);
}