mirror of
https://github.com/odin-lang/Odin.git
synced 2026-07-11 02:19:30 +00:00
fix issue 6853:
when iterating the values of an array literal,if one of the values is a function with multiple returns, it doesn't offset the struct field index by the number of values.
This commit is contained in:
@@ -1967,8 +1967,9 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isize multiple_return_offset = 0;
|
||||
for_array(i, cl->elems) {
|
||||
Entity *f = type->Struct.fields[i];
|
||||
Entity *f = type->Struct.fields[i+multiple_return_offset];
|
||||
TypeAndValue tav = cl->elems[i]->tav;
|
||||
|
||||
// INFO: dead code:
|
||||
@@ -1978,11 +1979,19 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty
|
||||
// val = tav.value;
|
||||
// }
|
||||
|
||||
if (is_type_tuple(tav.type)){
|
||||
multiple_return_offset += tav.type->Tuple.variables.count-1;
|
||||
}
|
||||
|
||||
i32 index = field_remapping[f->Variable.field_index];
|
||||
|
||||
|
||||
if (elem_type_can_be_constant(f->type)) {
|
||||
lbValue value = lb_const_value(m, f->type, tav.value, tav.type, cc);
|
||||
LLVMTypeRef value_type = LLVMTypeOf(value.value);
|
||||
GB_ASSERT_MSG(lb_sizeof(value_type) == type_size_of(f->type), "%s vs %s", LLVMPrintTypeToString(value_type), type_to_string(f->type));
|
||||
isize lb_sizeof_value_type = lb_sizeof(value_type);
|
||||
isize type_size_of_f_type = type_size_of(f->type);
|
||||
GB_ASSERT_MSG(lb_sizeof_value_type ==type_size_of_f_type, "%s vs %s", LLVMPrintTypeToString(value_type), type_to_string(f->type));
|
||||
values[index] = value.value;
|
||||
visited[index] = true;
|
||||
}
|
||||
|
||||
@@ -22,4 +22,9 @@ test_issue_6853 :: proc(t: ^testing.T) {
|
||||
case2 :: proc() -> (u64, u64) {return 2, 3}
|
||||
test2 := test_s{1, case2(), 4, 5}
|
||||
testing.expect_value(t, test2, expected)
|
||||
|
||||
case3_1 :: proc() -> (u64, u64) {return 1, 2}
|
||||
case3_2 :: proc() -> (u64, u64) {return 3, 4}
|
||||
test3 := test_s{case3_1(), case3_2(), 5}
|
||||
testing.expect_value(t, test3, expected)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user