mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:30:12 +01:00
Support unqualified lookup into extended interfaces from classes and impls (#7217)
When a class extends an interface, referring to a member name of the interface as an unqualified name should refer to the class's corresponding associated entity value, not to the associated entity itself. Similarly, in an `impl`, unqualified names of associated entities should refer to the `impl`'s corresponding value for that entity. To support this, we treat `impl`s as `extend`ing their implemented facet type, and we make lookups into an extended facet type use the `Self` type of the extending `impl` or `class` if lookup finds an associated entity. We already did the latter if the extending entity was an interface; this extends the existing support for these other cases.
This commit is contained in:
@@ -1925,6 +1925,8 @@ static auto ImportClassDefinition(ImportContext& context,
|
||||
context, import_scope, new_scope, new_class.first_owning_decl_id,
|
||||
SemIR::NameId::None, new_class.parent_scope_id);
|
||||
new_class.body_block_id = context.local_context().inst_block_stack().Pop();
|
||||
new_scope.set_self_type_id(
|
||||
context.local_types().GetTypeInstId(new_class.self_type_id));
|
||||
|
||||
if (import_class.base_id.has_value()) {
|
||||
new_class.base_id = base_id;
|
||||
@@ -2643,6 +2645,7 @@ static auto ImportImplDefinition(ImportContext& context,
|
||||
auto& new_scope = context.local_name_scopes().Get(new_impl.scope_id);
|
||||
new_scope.Set(new_impl.first_owning_decl_id, SemIR::NameId::None,
|
||||
new_impl.parent_scope_id);
|
||||
new_scope.set_self_type_id(new_impl.self_id);
|
||||
// Import the contents of the definition scope, if we might need it. Name
|
||||
// lookup is never performed into this scope by a user of the impl, so
|
||||
// this is only necessary in the same library that defined the impl, in
|
||||
@@ -3090,7 +3093,7 @@ static auto TryResolveTypedInst(ImportRefResolver& resolver,
|
||||
InitializeNameScopeAndImportRefs(resolver, import_scope, new_scope, decl_id,
|
||||
SemIR::NameId::None,
|
||||
local_interface.scope_without_self_id);
|
||||
new_scope.set_is_interface_definition();
|
||||
new_scope.set_self_type_id(local_interface.self_param_id);
|
||||
local_interface.associated_entities_id =
|
||||
AddAssociatedEntities(resolver, local_interface.scope_with_self_id,
|
||||
import_interface.associated_entities_id);
|
||||
|
||||
Reference in New Issue
Block a user