Parse vars in classes the same as vars in other locations (#7188)

Class vars are still restricted to simple `name: type` bindings, not
full patterns. This is now handled in the check phase instead of during
parsing.

This is in preparation for supporting `static var`.
This commit is contained in:
Nicholas Bishop
2026-05-13 21:22:46 +00:00
committed by GitHub
parent 5706601096
commit bd918fb33b
91 changed files with 370 additions and 660 deletions
+16
View File
@@ -40,6 +40,9 @@ class FullPatternStack {
// A name-binding declaration, such as a `let` or `var` statement.
NameBindingDecl,
// A non-static `var` field declaration inside a class.
FieldDecl,
// The implicit parameter list of a function or impl declaration.
ImplicitParamList,
@@ -62,6 +65,12 @@ class FullPatternStack {
// The kind of the current full-pattern.
auto CurrentKind() const -> Kind { return kind_stack_.back(); }
// Whether the kind of the current full-pattern is a non-static class
// `var` decl.
auto IsCurrentKindFieldDecl() -> bool {
return !empty() && CurrentKind() == Kind::FieldDecl;
}
// Marks the start of a new full-pattern for a parameterized entity
// declaration, such as a function or impl. The kind is initially
// NotInEitherParamList.
@@ -76,6 +85,13 @@ class FullPatternStack {
bind_name_stack_.PushArray();
}
// Marks the start of a new full-pattern for a non-staitc `var` field
// declaration.
auto PushFieldDecl() -> void {
kind_stack_.push_back(Kind::FieldDecl);
bind_name_stack_.PushArray();
}
// Marks the start of the current parameterized entity's implicit parameter
// list.
auto StartImplicitParamList() -> void {