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
+10
View File
@@ -7,6 +7,7 @@
#include "toolchain/check/inst.h"
#include "toolchain/check/pattern.h"
#include "toolchain/check/type.h"
#include "toolchain/diagnostics/emitter.h"
namespace Carbon::Check {
@@ -95,6 +96,15 @@ 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()) {
CARBON_DIAGNOSTIC(FieldWithTuplePattern, Error,
"found tuple pattern in class `var` decl");
context.emitter().Emit(LocIdForDiagnostics::TokenOnly(node_id),
FieldWithTuplePattern);
return false;
}
auto type_id = ExtractScrutineeType(context.sem_ir(),
context.insts().Get(inst).type_id());
type_inst_ids.push_back(context.types().GetTypeInstId(type_id));