Files
carbon-lang/toolchain/check/handle_match_first.cpp
T
Dana Jansens a46f4863db Basic checking for match_first blocks (#7481)
Push a scope_stack entry for match_first blocks, and handle impls being
inside those scope entries. An impl should not use the `match_first`
block as its "enclosing scope" for the purpose of deciding if the impl
is a redecl of another impl. We should look through it to the class or
namespace the impl (and match_first) are located inside.

We don't yet store the relationship between the impl and its match_first
block, nor then can we use it in impl lookup for prioritization.
2026-07-11 14:01:38 +00:00

32 lines
1017 B
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/check/context.h"
#include "toolchain/check/convert.h"
#include "toolchain/check/handle.h"
namespace Carbon::Check {
auto HandleParseNode(Context& /*context*/,
Parse::MatchFirstIntroducerId /*node_id*/) -> bool {
return true;
}
auto HandleParseNode(Context& context,
Parse::MatchFirstDefinitionStartId node_id) -> bool {
auto enclosing_scope_inst_id = context.scope_stack().PeekInstId();
auto decl_id = AddInst<SemIR::MatchFirstDecl>(
context, node_id, {.enclosing_scope_inst_id = enclosing_scope_inst_id});
context.scope_stack().PushForMatchFirstBlock(decl_id);
return true;
}
auto HandleParseNode(Context& context, Parse::MatchFirstId /*node_id*/)
-> bool {
context.scope_stack().Pop();
return true;
}
} // namespace Carbon::Check