mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:24:46 +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
@@ -100,16 +100,28 @@ static auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
|
||||
|
||||
// A `var` declaration at class scope introduces a field.
|
||||
auto parent_class_decl = context.GetCurrentScopeAs<SemIR::ClassDecl>();
|
||||
cast_type_id = context.AsCompleteType(cast_type_id, [&] {
|
||||
CARBON_DIAGNOSTIC(IncompleteTypeInVarDecl, Error,
|
||||
"{0} has incomplete type {1}", llvm::StringLiteral,
|
||||
InstIdAsType);
|
||||
return context.emitter().Build(type_node, IncompleteTypeInVarDecl,
|
||||
parent_class_decl
|
||||
? llvm::StringLiteral("Field")
|
||||
: llvm::StringLiteral("Variable"),
|
||||
cast_type_inst_id);
|
||||
});
|
||||
cast_type_id = context.AsCompleteType(
|
||||
cast_type_id,
|
||||
[&] {
|
||||
CARBON_DIAGNOSTIC(IncompleteTypeInVarDecl, Error,
|
||||
"{0} has incomplete type {1}",
|
||||
llvm::StringLiteral, SemIR::TypeId);
|
||||
return context.emitter().Build(
|
||||
type_node, IncompleteTypeInVarDecl,
|
||||
parent_class_decl ? llvm::StringLiteral("field")
|
||||
: llvm::StringLiteral("variable"),
|
||||
cast_type_id);
|
||||
},
|
||||
[&] {
|
||||
CARBON_DIAGNOSTIC(AbstractTypeInVarDecl, Error,
|
||||
"{0} has abstract type {1}", llvm::StringLiteral,
|
||||
SemIR::TypeId);
|
||||
return context.emitter().Build(
|
||||
type_node, AbstractTypeInVarDecl,
|
||||
parent_class_decl ? llvm::StringLiteral("field")
|
||||
: llvm::StringLiteral("variable"),
|
||||
cast_type_id);
|
||||
});
|
||||
if (parent_class_decl) {
|
||||
CARBON_CHECK(context_node_kind == Parse::NodeKind::VariableIntroducer,
|
||||
"`returned var` at class scope");
|
||||
|
||||
Reference in New Issue
Block a user