From 3883d079c8cf78ad49c6b140cf37b943c27c27c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A4rtschi=20Robin?= Date: Wed, 24 Jun 2026 08:04:17 +0200 Subject: [PATCH 1/3] Fix #6874 --- core/encoding/json/types.odin | 1 + src/check_stmt.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/core/encoding/json/types.odin b/core/encoding/json/types.odin index 77cc7db85..6b6d8aae9 100644 --- a/core/encoding/json/types.odin +++ b/core/encoding/json/types.odin @@ -113,6 +113,7 @@ destroy_value :: proc(value: Value, allocator := context.allocator, loc := #call } clone_value :: proc(value: Value, allocator := context.allocator) -> Value { + value := value context.allocator = allocator #partial switch &v in value { diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 53dae5fd5..222222559 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1476,6 +1476,14 @@ gb_internal void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_ return; } + if (switch_kind == TypeSwitch_Union) { + if (is_addressed) { + if (x.mode != Addressing_Variable && !is_type_pointer(x.type)) { + error(lhs->Ident.token, "The element variable '%.*s' cannot be made addressable", LIT(lhs->Ident.token.string)); + } + } + } + Ast *nil_seen = nullptr; TypeSet seen = {}; From 640a0f2ef49b347f0a10dd6b1c2034306352a9df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A4rtschi=20Robin?= Date: Wed, 24 Jun 2026 08:31:46 +0200 Subject: [PATCH 2/3] add test for #6874 --- tests/issues/run.bat | 1 + tests/issues/run.sh | 6 ++++++ tests/issues/test_issue_6874.odin | 35 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 tests/issues/test_issue_6874.odin diff --git a/tests/issues/run.bat b/tests/issues/run.bat index 0b92f07ff..43a7136b7 100644 --- a/tests/issues/run.bat +++ b/tests/issues/run.bat @@ -36,6 +36,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused ..\..\..\odin test ..\test_pr_6470.odin -define:TEST_EXPECT_FAILURE=true %COMMON% 2>&1 | find /c "Error:" | findstr /x "1" || exit /b ..\..\..\odin test ..\test_pr_6476.odin %COMMON% || exit /b ..\..\..\odin check ..\test_issue_6484.odin -no-entry-point %COMMON% || exit /b +..\..\..\odin check ..\test_issue_6874.odin %COMMON% 2>&1 | find /c "Error:" | findstr /x "1" || exit /b @echo off diff --git a/tests/issues/run.sh b/tests/issues/run.sh index f630738f9..3633a7606 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -73,6 +73,12 @@ else exit 1 fi $ODIN check ../test_issue_6484.odin -no-entry-point $COMMON +if [[ $($ODIN check ../test_issue_6874.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 1 ]] ; then + echo "SUCCESSFUL 1/1" +else + echo "SUCCESSFUL 0/1" + exit 1 +fi set +x diff --git a/tests/issues/test_issue_6874.odin b/tests/issues/test_issue_6874.odin new file mode 100644 index 000000000..751e12ebe --- /dev/null +++ b/tests/issues/test_issue_6874.odin @@ -0,0 +1,35 @@ +// Test for issue #6874 https://github.com/odin-lang/Odin/issues/6874 + +package test_issues + +import "core:fmt" + +PersonData :: struct { + health: int, + age: int, +} + +MyUnion :: union { + f32, + int, + PersonData, +} + +change_union_data :: proc(data: MyUnion) { + switch &v in data { + case int: + v = 10 + case f32: + fmt.println("f32") + case PersonData: + fmt.println("PersonData") + fmt.println(v) + } +} + +main :: proc() { + val: MyUnion = int(12) + fmt.printfln("Before the call: %v", val) + change_union_data(val) + fmt.printfln("After the call: %v", val) +} \ No newline at end of file From 212004b3ad147b0e765db281d1f3cb394eac6efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A4rtschi=20Robin?= Date: Wed, 24 Jun 2026 08:41:29 +0200 Subject: [PATCH 3/3] test_issue_6874: fix formatting --- tests/issues/test_issue_6874.odin | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/issues/test_issue_6874.odin b/tests/issues/test_issue_6874.odin index 751e12ebe..946fef39d 100644 --- a/tests/issues/test_issue_6874.odin +++ b/tests/issues/test_issue_6874.odin @@ -5,31 +5,31 @@ package test_issues import "core:fmt" PersonData :: struct { - health: int, - age: int, + health: int, + age: int, } MyUnion :: union { - f32, - int, - PersonData, + f32, + int, + PersonData, } change_union_data :: proc(data: MyUnion) { - switch &v in data { - case int: - v = 10 - case f32: - fmt.println("f32") - case PersonData: - fmt.println("PersonData") - fmt.println(v) - } + switch &v in data { + case int: + v = 10 + case f32: + fmt.println("f32") + case PersonData: + fmt.println("PersonData") + fmt.println(v) + } } main :: proc() { - val: MyUnion = int(12) - fmt.printfln("Before the call: %v", val) - change_union_data(val) - fmt.printfln("After the call: %v", val) -} \ No newline at end of file + val: MyUnion = int(12) + fmt.printfln("Before the call: %v", val) + change_union_data(val) + fmt.printfln("After the call: %v", val) +}