mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 09:11:05 +01:00
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:
co-authored by
Richard Smith
parent
bafddd8711
commit
d491387a98
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user