Skip to content

Commit e26b6a3

Browse files
authored
Allow instance binding on tuple-valued expressions. (#6203)
Don't expect the right-hand operand of `a.(b)` to always be a tuple index when `a` is of tuple type; it could also be a method name. Fixes #6162.
1 parent 1ac1d11 commit e26b6a3

File tree

5 files changed

+296
-199
lines changed

5 files changed

+296
-199
lines changed

toolchain/check/member_access.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,9 +742,6 @@ auto PerformCompoundMemberAccess(Context& context, SemIR::LocId loc_id,
742742
return GetAssociatedValueImpl(context, loc_id, base_id, assoc_entity,
743743
assoc_type->GetSpecificInterface());
744744
}
745-
} else if (context.insts().Is<SemIR::TupleType>(
746-
context.constant_values().GetInstId(base_type_const_id))) {
747-
return PerformTupleAccess(context, loc_id, base_id, member_expr_id);
748745
}
749746

750747
// Perform instance binding if we found an instance member.
@@ -754,6 +751,13 @@ auto PerformCompoundMemberAccess(Context& context, SemIR::LocId loc_id,
754751
// because the base expression is not used for anything.
755752
if (member_id == member_expr_id &&
756753
member.type_id() != SemIR::ErrorInst::TypeId) {
754+
// As a special case, an integer-valued expression can be used as a member
755+
// name when indexing a tuple.
756+
if (context.insts().Is<SemIR::TupleType>(
757+
context.constant_values().GetInstId(base_type_const_id))) {
758+
return PerformTupleAccess(context, loc_id, base_id, member_expr_id);
759+
}
760+
757761
CARBON_DIAGNOSTIC(CompoundMemberAccessDoesNotUseBase, Error,
758762
"member name of type {0} in compound member access is "
759763
"not an instance member or an interface member",

0 commit comments

Comments
 (0)