Stop pushing a fake generic for the duration of check. (#5326)

This fake generic was used for two reasons:

- The declaration name stack assumes that each declaration name is
processed within a generic scope. This is important if the name might
have generic parameters, which are always parsed even for declarations
that disallow them in check.
- Out-of-line redeclarations of generic entities produce instructions
with symbolic constant values in non-generic scopes.

The former case is addressed by pushing a generic each time we start a
declaration name, even if we will reject generic parameters later. The
latter case is worked around for now by not building a symbolic constant
type or value for instructions that appear outside of any generic, and
will be addressed more completely by #5310 and follow-ups.
This commit is contained in:
Richard Smith
2025-04-17 21:58:37 +00:00
committed by GitHub
parent 886dc842f0
commit 19532967fa
10 changed files with 47 additions and 21 deletions
+2 -2
View File
@@ -40,6 +40,8 @@ namespace Carbon::Check {
auto HandleParseNode(Context& context, Parse::FunctionIntroducerId node_id)
-> bool {
// The function is potentially generic.
StartGenericDecl(context);
// Create an instruction block to hold the instructions created as part of the
// function signature, such as parameter and return types.
context.inst_block_stack().Push();
@@ -48,8 +50,6 @@ auto HandleParseNode(Context& context, Parse::FunctionIntroducerId node_id)
// Optional modifiers and the name follow.
context.decl_introducer_state_stack().Push<Lex::TokenKind::Fn>();
context.decl_name_stack().PushScopeAndStartName();
// The function is potentially generic.
StartGenericDecl(context);
return true;
}