Implement static var class fields (#7215)

This adds the `static` token to the lexer and parses it as a modifier.

In check, `FullPatternStack::Kind::FieldDecl` is now used for both
static and non-static vars. Static vars get treated basically the same
as `NameBindingDecl`s.

Global initialization is used for static var initializers. To make the
necessary stack information available to `pattern_match.cpp`, the
`full_pattern_stack` and `decl_introducer_state_stack` are now popped
later in `handle_let_and_var.cpp`.

In lowering, each class's body is checked for `VarStorage` insts and
lowered the same as global vars.
This commit is contained in:
Nicholas Bishop
2026-05-18 20:09:17 +00:00
committed by GitHub
parent 31db4a0931
commit 773ecdfac6
21 changed files with 380 additions and 69 deletions
+2 -2
View File
@@ -136,8 +136,8 @@ auto AddBindingPattern(Context& context, SemIR::LocId name_loc,
}
auto type_id = SemIR::ExtractScrutineeType(context.sem_ir(), pattern.type_id);
// Handle `var` decls in a class by creating a `FieldDecl`.
if (context.full_pattern_stack().IsCurrentKindFieldDecl()) {
// Handle non-static `var` decls in a class by creating a `FieldDecl`.
if (InNonStaticFieldDecl(context)) {
auto class_decl =
context.scope_stack().TryGetCurrentScopeAs<SemIR::ClassDecl>();
auto name_id = context.entity_names().Get(pattern.entity_name_id).name_id;