add test for #6874

This commit is contained in:
Bärtschi Robin
2026-06-24 08:31:46 +02:00
parent 3883d079c8
commit 640a0f2ef4
3 changed files with 42 additions and 0 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)
}