From d65d743ab71fc5da9f23ea519e64f0a10da9f912 Mon Sep 17 00:00:00 2001 From: Louis Novy <101842021+louisnovy@users.noreply.github.com> Date: Sat, 26 Sep 2026 22:22:42 -0400 Subject: [PATCH] Fix full length swizzles through a pointer keeping the pointer type --- src/check_expr.cpp | 4 ++-- tests/issues/run.bat | 1 + tests/issues/run.sh | 1 + tests/issues/test_issue_7587.odin | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/issues/test_issue_7587.odin diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 758d7a5fd..fade7a46c 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -5830,7 +5830,7 @@ gb_internal Type *determine_swizzle_array_type(Type *original_type, Type *type_h Type *elem_type = array_type->Array.elem; Type *swizzle_array_type = nullptr; - Type *bth = base_type(type_deref(type_hint)); + Type *bth = base_type(type_hint); if (bth != nullptr && bth->kind == Type_Array && bth->Array.count == new_count && are_types_identical(bth->Array.elem, elem_type)) { @@ -5838,7 +5838,7 @@ gb_internal Type *determine_swizzle_array_type(Type *original_type, Type *type_h } else { i64 max_count = array_type->Array.count; if (new_count == max_count) { - swizzle_array_type = original_type; + swizzle_array_type = type_deref(original_type); } else { swizzle_array_type = alloc_type_array(elem_type, new_count); } diff --git a/tests/issues/run.bat b/tests/issues/run.bat index 0a3127946..f19e17313 100644 --- a/tests/issues/run.bat +++ b/tests/issues/run.bat @@ -61,6 +61,7 @@ clang -c ..\test_issue_sysv_abi.c -o test_issue_sysv_abi_c.o || exit /b ..\..\..\odin run ..\test_issue_7482.odin %COMMON% || exit /b ..\..\..\odin run ..\test_issue_7562.odin %COMMON% -no-crt -no-thread-local || exit /b ..\..\..\odin run ..\test_issue_7562.odin %COMMON% -no-crt -no-thread-local -o:speed || exit /b +..\..\..\odin test ..\test_issue_7587.odin %COMMON% || exit /b @echo off diff --git a/tests/issues/run.sh b/tests/issues/run.sh index 08d2db369..eb889fa41 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -92,6 +92,7 @@ $ODIN check ../test_issue_7012.odin -no-entry-point $COMMON_CHECK $ODIN build ../test_issue_7037.odin $COMMON -o:none $ODIN run ../test_issue_7482.odin $COMMON $ODIN run ../test_issue_7564.odin $COMMON +$ODIN test ../test_issue_7587.odin $COMMON $ODIN test ../test_issue_7421.odin $COMMON if [[ $($ODIN check ../test_issue_7421_tagged_duplicate.odin $COMMON_CHECK 2>&1 >/dev/null | grep -c "Error: Duplicate case") -eq 1 ]]; then echo "SUCCESSFUL 1/1" diff --git a/tests/issues/test_issue_7587.odin b/tests/issues/test_issue_7587.odin new file mode 100644 index 000000000..c6458a9a7 --- /dev/null +++ b/tests/issues/test_issue_7587.odin @@ -0,0 +1,16 @@ +// Tests issue #7587 https://github.com/odin-lang/Odin/issues/7587 +package test_issues + +import "core:testing" + +@(test) +test_issue_7587 :: proc(t: ^testing.T) { + v := [4]f32{1, 2, 3, 4} + p := &v + + w := p.wzyx + testing.expect_value(t, w, [4]f32{4, 3, 2, 1}) + + p.wzyx = {1, 2, 3, 4} + testing.expect_value(t, v, [4]f32{4, 3, 2, 1}) +}