Merge pull request #6880 from RoBaertschi/master

Fix #6874
This commit is contained in:
gingerBill
2026-06-24 10:36:20 +01:00
committed by GitHub
5 changed files with 51 additions and 0 deletions

View File

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

View File

@@ -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 = {};

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