mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
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:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user