mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -2,6 +2,7 @@
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "toolchain/check/class.h"
|
||||
#include "toolchain/check/context.h"
|
||||
#include "toolchain/check/handle.h"
|
||||
#include "toolchain/check/inst.h"
|
||||
@@ -96,7 +97,7 @@ auto HandleParseNode(Context& context, Parse::TuplePatternId node_id) -> bool {
|
||||
llvm::SmallVector<SemIR::InstId> type_inst_ids;
|
||||
type_inst_ids.reserve(inst_block.size());
|
||||
for (auto inst : inst_block) {
|
||||
if (context.full_pattern_stack().IsCurrentKindFieldDecl()) {
|
||||
if (InNonStaticFieldDecl(context)) {
|
||||
CARBON_DIAGNOSTIC(FieldWithTuplePattern, Error,
|
||||
"found tuple pattern in class `var` decl");
|
||||
context.emitter().Emit(LocIdForDiagnostics::TokenOnly(node_id),
|
||||
|
||||
Reference in New Issue
Block a user