mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user