Fix accessing members of const/partial types (#7406)

In `PerformActionHelper`, use the unqualified type for lookup.

In `PerformInstanceBinding`, propagate qualifiers to the unbound element
type's class type when doing the `ConvertToValueOrRefOfType` conversion,
and to the element type when forming the `ClassElementAccess` instr
(except for `partial`, which is only used if the member being accessed
is `base`).

In handle_operator.cpp, prevent assignment to a reference to a const
type.
This commit is contained in:
Nicholas Bishop
2026-06-25 00:07:39 +00:00
committed by GitHub
parent 885b1110d5
commit 36d9bed4ca
5 changed files with 202 additions and 11 deletions
+6 -2
View File
@@ -104,9 +104,13 @@ auto HandleParseNode(Context& context, Parse::InfixOperatorEqualId node_id)
auto [rhs_node, rhs_id] = context.node_stack().PopExprWithNodeId();
auto [lhs_node, lhs_id] = context.node_stack().PopExprWithNodeId();
auto lhs_type_id = context.insts().Get(lhs_id).type_id();
auto lhs_quals =
context.types().GetUnqualifiedTypeAndQualifiers(lhs_type_id).second;
if (auto lhs_cat = SemIR::GetExprCategory(context.sem_ir(), lhs_id);
lhs_cat != SemIR::ExprCategory::DurableRef &&
lhs_cat != SemIR::ExprCategory::Error) {
(lhs_cat != SemIR::ExprCategory::DurableRef &&
lhs_cat != SemIR::ExprCategory::Error) ||
lhs_quals.HasAnyOf(SemIR::TypeQualifiers::Const)) {
CARBON_DIAGNOSTIC(AssignmentToNonAssignable, Error,
"expression is not assignable");
context.emitter().Emit(lhs_node, AssignmentToNonAssignable);