Fix formation of invalid value_of_initializer instructions. (#7329)

This is only valid when the operand is an initializing expression that
holds a copy of the value, but we were incorrectly also forming it when
the operand was an in-place initializing expression.

Fixes a crash in lowering when attempting to lower an invalid
`value_of_initializer`.
This commit is contained in:
Richard Smith
2026-06-10 15:28:56 +00:00
committed by GitHub
parent 41e3c9bd82
commit fb05da761f
3 changed files with 376 additions and 2 deletions
+3
View File
@@ -2078,7 +2078,10 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
});
// Pull a value directly out of the initializer if possible and wanted.
// TODO: Should this be done as part of category conversion instead?
if (expr_id != SemIR::ErrorInst::InstId &&
SemIR::GetExprCategory(sem_ir, expr_id) ==
SemIR::ExprCategory::ReprInitializing &&
CanUseValueOfInitializer(sem_ir, target.type_id, target.kind)) {
expr_id = AddInst<SemIR::ValueOfInitializer>(
context, loc_id, {.type_id = target.type_id, .init_id = expr_id});