mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Require extend before base: BaseType; (#3459)
This commit is contained in:
@@ -165,8 +165,8 @@ auto HandleClassDefinitionStart(Context& context, Parse::NodeId parse_node)
|
||||
return true;
|
||||
}
|
||||
|
||||
auto HandleBaseIntroducer(Context& /*context*/, Parse::NodeId /*parse_node*/)
|
||||
-> bool {
|
||||
auto HandleBaseIntroducer(Context& context, Parse::NodeId parse_node) -> bool {
|
||||
context.decl_state_stack().Push(DeclState::Base, parse_node);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -178,6 +178,18 @@ auto HandleBaseColon(Context& /*context*/, Parse::NodeId /*parse_node*/)
|
||||
auto HandleBaseDecl(Context& context, Parse::NodeId parse_node) -> bool {
|
||||
auto base_type_expr_id = context.node_stack().PopExpr();
|
||||
|
||||
// Process modifiers. `extend` is required, none others are allowed.
|
||||
LimitModifiersOnDecl(context, KeywordModifierSet::Extend,
|
||||
Lex::TokenKind::Base);
|
||||
auto modifiers = context.decl_state_stack().innermost().modifier_set;
|
||||
if (!(modifiers & KeywordModifierSet::Extend)) {
|
||||
CARBON_DIAGNOSTIC(BaseMissingExtend, Error,
|
||||
"Missing `extend` before `base` declaration in class.");
|
||||
context.emitter().Emit(context.decl_state_stack().innermost().first_node,
|
||||
BaseMissingExtend);
|
||||
}
|
||||
context.decl_state_stack().Pop(DeclState::Base);
|
||||
|
||||
auto enclosing_class_decl = context.GetCurrentScopeAs<SemIR::ClassDecl>();
|
||||
if (!enclosing_class_decl) {
|
||||
CARBON_DIAGNOSTIC(BaseOutsideClass, Error,
|
||||
|
||||
Reference in New Issue
Block a user