Fix indirect import handling for functions. (#4258)

The particular test this focused on is indirect_two_file in
toolchain/check/testdata/function/definition/no_prelude/extern_library.carbon.

This removes `parent_scope_id_for_new_inst` because I think it's
returning unhelpful results. The use was at the root of incorrect
results for the indirect import chain. `name_id_for_new_inst` is
actually wrapping a union, so it's more important.

The merging of `is_extern` and `first_owning_decl_id` in
`handle_function.cpp` feels like it's less correct with the changes
that've been made to `extern`. This ripples in tests, because the error
recovery shifts.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2024-08-27 20:26:23 +00:00
committed by GitHub
co-authored by Richard Smith
parent 2a7c2c5df2
commit bed5fdcbbe
16 changed files with 139 additions and 79 deletions
+1 -8
View File
@@ -96,7 +96,7 @@ class DeclNameStack {
-> SemIR::EntityWithParamsBase {
return {
.name_id = name_id_for_new_inst(),
.parent_scope_id = parent_scope_id_for_new_inst(),
.parent_scope_id = parent_scope_id,
.generic_id = SemIR::GenericId::Invalid,
.first_param_node_id = name.first_param_node_id,
.last_param_node_id = name.last_param_node_id,
@@ -121,13 +121,6 @@ class DeclNameStack {
: SemIR::NameId::Invalid;
}
// Returns the parent_scope_id for a new instruction. This is invalid
// when the name resolved.
auto parent_scope_id_for_new_inst() -> SemIR::NameScopeId {
return state == State::Unresolved ? parent_scope_id
: SemIR::NameScopeId::Invalid;
}
// The current scope when this name began. This is the scope that we will
// return to at the end of the declaration.
ScopeIndex initial_scope_index;