| ... | @@ -18477,6 +18477,15 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr | ... | @@ -18477,6 +18477,15 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 18477 | IrInstGen *casted_ptr; | 18477 | IrInstGen *casted_ptr; |
| 18478 | if (isf->already_resolved) { | 18478 | if (isf->already_resolved) { |
| 18479 | field = find_struct_type_field(isf->inferred_struct_type, isf->field_name); | 18479 | field = find_struct_type_field(isf->inferred_struct_type, isf->field_name); |
| | 18480 | |
| | 18481 | // If the value originates from another node than the original value's we overwrite the inferred struct's |
| | 18482 | // type so that the new result can be written successfully. |
| | 18483 | // The duplicate field will be detected and reported in 'ir_analyze_container_init_fields' |
| | 18484 | AstNode *decl_node = value ? value->base.source_node : suspend_source_instr->source_node; |
| | 18485 | if (decl_node != field->decl_node) { |
| | 18486 | field->type_entry = value_type; |
| | 18487 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| | 18488 | } |
| 18480 | casted_ptr = result_loc; | 18489 | casted_ptr = result_loc; |
| 18481 | } else { | 18490 | } else { |
| 18482 | isf->already_resolved = true; | 18491 | isf->already_resolved = true; |
| ... | @@ -18493,15 +18502,6 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr | ... | @@ -18493,15 +18502,6 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 18493 | field->type_val = create_const_type(ira->codegen, field->type_entry); | 18502 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| 18494 | field->src_index = old_field_count; | 18503 | field->src_index = old_field_count; |
| 18495 | field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node; | 18504 | field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node; |
| 18496 | if (value && instr_is_comptime(value)) { | | |
| 18497 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); | | |
| 18498 | if (!val) | | |
| 18499 | return ira->codegen->invalid_inst_gen; | | |
| 18500 | field->is_comptime = true; | | |
| 18501 | field->init_val = ira->codegen->pass1_arena->create<ZigValue>(); | | |
| 18502 | copy_const_val(ira->codegen, field->init_val, val); | | |
| 18503 | return result_loc; | | |
| 18504 | } | | |
| 18505 | | 18505 | |
| 18506 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); | 18506 | ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false); |
| 18507 | if (instr_is_comptime(result_loc)) { | 18507 | if (instr_is_comptime(result_loc)) { |
| ... | @@ -18532,6 +18532,16 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr | ... | @@ -18532,6 +18532,16 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr |
| 18532 | } | 18532 | } |
| 18533 | } | 18533 | } |
| 18534 | | 18534 | |
| | 18535 | if (value && instr_is_comptime(value)) { |
| | 18536 | ZigValue *val = ir_resolve_const(ira, value, UndefOk); |
| | 18537 | if (!val) |
| | 18538 | return ira->codegen->invalid_inst_gen; |
| | 18539 | field->is_comptime = true; |
| | 18540 | field->init_val = ira->codegen->pass1_arena->create<ZigValue>(); |
| | 18541 | copy_const_val(ira->codegen, field->init_val, val); |
| | 18542 | return result_loc; |
| | 18543 | } |
| | 18544 | |
| 18535 | result_loc = ir_analyze_struct_field_ptr(ira, suspend_source_instr, field, casted_ptr, | 18545 | result_loc = ir_analyze_struct_field_ptr(ira, suspend_source_instr, field, casted_ptr, |
| 18536 | isf->inferred_struct_type, true); | 18546 | isf->inferred_struct_type, true); |
| 18537 | result_loc_pass1->resolved_loc = result_loc; | 18547 | result_loc_pass1->resolved_loc = result_loc; |
| ... | @@ -22957,6 +22967,9 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc | ... | @@ -22957,6 +22967,9 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 22957 | first_non_const_instruction = result_loc; | 22967 | first_non_const_instruction = result_loc; |
| 22958 | } | 22968 | } |
| 22959 | } | 22969 | } |
| | 22970 | |
| | 22971 | heap::c_allocator.deallocate(field_assign_nodes, actual_field_count); |
| | 22972 | |
| 22960 | if (any_missing) | 22973 | if (any_missing) |
| 22961 | return ira->codegen->invalid_inst_gen; | 22974 | return ira->codegen->invalid_inst_gen; |
| 22962 | | 22975 | |
| ... | @@ -22972,6 +22985,8 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc | ... | @@ -22972,6 +22985,8 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc |
| 22972 | } | 22985 | } |
| 22973 | } | 22986 | } |
| 22974 | | 22987 | |
| | 22988 | const_ptrs.deinit(); |
| | 22989 | |
| 22975 | IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr); | 22990 | IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr); |
| 22976 | | 22991 | |
| 22977 | if (is_comptime && !instr_is_comptime(result)) { | 22992 | if (is_comptime && !instr_is_comptime(result)) { |