mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 06:41:06 +01:00
Perform member lookup on FacetAccessType (#5058)
The name scope lookup and member name lookup both need to handle the case where the base inst is a FacetAccessType. Then we move from the FacetAccessType to the FacetType which is the type of the instruction inside the FacetAccessType. We do name lookup on FacetType already, so "unwrapping" the FacetAccessType to the FacetType just makes use of that path. Similarly we do member access on FacetType already, so we can reuse that codepath with the FacetType found in the FacetAccessType.
This commit is contained in:
@@ -287,8 +287,16 @@ static auto LookupMemberNameInScope(Context& context, SemIR::LocId loc_id,
|
||||
context.types().TryGetAs<SemIR::AssociatedEntityType>(type_id)) {
|
||||
if (lookup_in_type_of_base) {
|
||||
SemIR::TypeId base_type_id = context.insts().Get(base_id).type_id();
|
||||
if (base_type_id != SemIR::TypeType::SingletonTypeId &&
|
||||
context.types().IsFacetType(base_type_id)) {
|
||||
if (auto facet_access_type =
|
||||
context.types().TryGetAs<SemIR::FacetAccessType>(base_type_id)) {
|
||||
// Move from the type of a symbolic facet value up in typish-ness to its
|
||||
// FacetType to find the type to work with.
|
||||
base_id = facet_access_type->facet_value_inst_id;
|
||||
base_type_id = context.insts().Get(base_id).type_id();
|
||||
}
|
||||
|
||||
if (auto facet_type =
|
||||
context.types().TryGetAs<SemIR::FacetType>(base_type_id)) {
|
||||
// Handles `T.F` when `T` is a non-type facet.
|
||||
auto base_as_type = ExprAsType(context, loc_id, base_id);
|
||||
|
||||
@@ -301,9 +309,8 @@ static auto LookupMemberNameInScope(Context& context, SemIR::LocId loc_id,
|
||||
// First look for `*assoc_interface` in the type of the base. If it is
|
||||
// found, get the witness that the interface is implemented from
|
||||
// `base_id`.
|
||||
auto facet_type = context.types().GetAs<SemIR::FacetType>(base_type_id);
|
||||
const auto& facet_type_info =
|
||||
context.facet_types().Get(facet_type.facet_type_id);
|
||||
context.facet_types().Get(facet_type->facet_type_id);
|
||||
// Witness that `T` implements the `*assoc_interface`.
|
||||
SemIR::InstId witness_inst_id = SemIR::InstId::None;
|
||||
for (auto base_interface : facet_type_info.impls_constraints) {
|
||||
|
||||
Reference in New Issue
Block a user