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