Files
carbon-lang/toolchain/check/name_scope.h
T
Dana Jansens 2d38978756 Diagnose explicit Self in extend in the parse node handler (Refactor Impl construction 1/7) (#6465)
We encode the state of looking that the parent scope is a Class into a
type so that we can avoid extra lookups. Then use that in refactoring
where diagnostics are generated for an explicit `Self` in an `extend
impl` declaration.

We add tests that we don't double-diagnose the Self type when it's
already an error, and make the behaviour of `extend require` match that
of `extend impl as`.

This avoids some fragile/complex parse-node lookups (such as
`context.parse_tree_and_subtrees().ExtractAs<Parse::ImplTypeAs>`) by
using the parse node at the point where we are handling it instead of
much later.

This is part of #6420 which is being split up into a chain of smaller
PRs.
2025-12-09 20:38:50 +00:00

29 lines
818 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
#ifndef CARBON_TOOLCHAIN_CHECK_NAME_SCOPE_H_
#define CARBON_TOOLCHAIN_CHECK_NAME_SCOPE_H_
#include <optional>
#include "toolchain/check/context.h"
#include "toolchain/sem_ir/ids.h"
#include "toolchain/sem_ir/typed_insts.h"
namespace Carbon::Check {
struct ClassScope {
SemIR::ClassDecl class_decl;
SemIR::NameScope* name_scope;
};
// If the specified name scope corresponds to a class, returns the corresponding
// class declaration.
auto TryAsClassScope(Context& context, SemIR::NameScopeId scope_id)
-> std::optional<ClassScope>;
} // namespace Carbon::Check
#endif // CARBON_TOOLCHAIN_CHECK_NAME_SCOPE_H_