mirror of
https://github.com/odin-lang/Odin.git
synced 2026-10-09 06:12:05 -04:00
Fix the length of fixed capacity dynamic array literals whose elements can't be constant
This commit is contained in:
1 parent
40f3df53bb
commit
4a3a7a92cb
4 files changed
+20
-2
No files matched your search
@@ -6458,13 +6458,16 @@ gb_internal lbAddr lb_build_addr_compound_lit(lbProcedure *p, Ast *expr) {
|
||||
|
||||
case Type_FixedCapacityDynamicArray: {
|
||||
if (cl->elems.count > 0) {
|
||||
lb_addr_store(p, v, lb_const_value(p->module, type, exact_value_compound(expr)));
|
||||
// NOTE: the length isn't taken from the literal's constant, which is nil when its elements can't be constant
|
||||
lbValue dst_ptr = lb_addr_get_ptr(p, v);
|
||||
lbValue value = lb_const_value(p->module, type, exact_value_compound(expr));
|
||||
lb_emit_store(p, lb_emit_struct_ep(p, dst_ptr, 0), lb_emit_struct_ev(p, value, 0));
|
||||
lb_emit_store(p, lb_emit_struct_ep(p, dst_ptr, 1), lb_const_int(p->module, t_int, cl->max_count));
|
||||
|
||||
auto temp_data = array_make<lbCompoundLitElemTempData>(temporary_allocator(), 0, cl->elems.count);
|
||||
|
||||
lb_build_addr_compound_lit_populate(p, cl->elems, &temp_data, type);
|
||||
|
||||
lbValue dst_ptr = lb_addr_get_ptr(p, v);
|
||||
for_array(i, temp_data) {
|
||||
i32 index = cast(i32)(temp_data[i].elem_index);
|
||||
temp_data[i].gep = lb_emit_array_epi(p, dst_ptr, index);
|
||||
|
||||
@@ -59,6 +59,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused
|
||||
..\..\..\odin build ..\test_issue_7037.odin %COMMON% -o:none || exit /b
|
||||
..\..\..\odin test ..\test_issue_7421.odin %COMMON% || exit /b
|
||||
..\..\..\odin check ..\test_issue_7421_tagged_duplicate.odin %COMMON% 2>&1 | find /c "Error: Duplicate case" | findstr /x "1" || exit /b
|
||||
..\..\..\odin test ..\test_issue_7430.odin %COMMON% || exit /b
|
||||
..\..\..\odin build ..\test_issue_7188.odin %COMMON% || exit /b
|
||||
clang -c ..\test_issue_sysv_abi.c -o test_issue_sysv_abi_c.o || exit /b
|
||||
..\..\..\odin test ..\test_issue_sysv_abi.odin %COMMON% || exit /b
|
||||
|
||||
@@ -112,6 +112,7 @@ else
|
||||
exit 1
|
||||
fi
|
||||
$ODIN check ../test_issue_7429.odin $COMMON_CHECK
|
||||
$ODIN test ../test_issue_7430.odin $COMMON
|
||||
$ODIN test ../test_issue_7356.odin $COMMON
|
||||
$ODIN test ../test_issue_7336.odin $COMMON
|
||||
$ODIN build ../test_issue_7167.odin $COMMON
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Tests issue #7430 https://github.com/odin-lang/Odin/issues/7430
|
||||
package test_issues
|
||||
|
||||
import "core:testing"
|
||||
|
||||
@(test)
|
||||
test_issue_7430 :: proc(t: ^testing.T) {
|
||||
U :: union {T}
|
||||
T :: struct {_: []i32}
|
||||
|
||||
u := [dynamic; 4]U{T{}}
|
||||
testing.expect_value(t, len(u), 1)
|
||||
}
|
||||
Reference in new issue
Block a user