fix #7596 and #7511: proc literal as union variant in compound literal crashes backend

This commit is contained in:
Fernando Nunes committed 2026-09-25 07:08:01 -03:00
1 parent f1fd03364d
commit bc68304497
4 files changed
+29 -1

No files matched your search

+3 -1
View File
@@ -9527,7 +9527,9 @@ gb_internal bool check_is_operand_compound_lit_constant(CheckerContext *c, Opera
return true;
}
if (expr->kind == Ast_ProcLit) {
add_type_and_value(c, expr, Addressing_Constant, type_of_expr(expr), exact_value_procedure(expr));
ExactValue value = exact_value_procedure(expr);
value.variant_type = o->value.variant_type;
add_type_and_value(c, expr, Addressing_Constant, type_of_expr(expr), value);
return true;
}
+1
View File
@@ -60,6 +60,7 @@ clang -c ..\test_issue_sysv_abi.c -o test_issue_sysv_abi_c.o || exit /b
..\..\..\odin test ..\test_issue_swizzle_multi_assign.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 run ..\test_issue_7596.odin %COMMON% || exit /b
@echo off
+1
View File
@@ -91,6 +91,7 @@ $ODIN test ../test_issue_7008.odin $COMMON
$ODIN check ../test_issue_7012.odin -no-entry-point $COMMON_CHECK
$ODIN build ../test_issue_7037.odin $COMMON -o:none
$ODIN run ../test_issue_7564.odin $COMMON
$ODIN run ../test_issue_7596.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"
+24
View File
@@ -0,0 +1,24 @@
// Tests issue #7596 and #7511: a procedure literal converted to a union variant inside a
// compound literal crashed the backend with `value_type != nullptr`.
// https://github.com/odin-lang/Odin/issues/7596
package test_issues
P :: proc() -> int
U :: union {P, int}
S :: struct {
u: U,
m: Maybe(P),
}
global_slice := []U{proc() -> int { return 1 }, 2}
global_struct := S{u = proc() -> int { return 3 }, m = proc() -> int { return 4 }}
main :: proc() {
local := [1]U{proc() -> int { return 5 }}
assert(global_slice[0].(P)() == 1)
assert(global_slice[1].(int) == 2)
assert(global_struct.u.(P)() == 3)
assert(global_struct.m.?() == 4)
assert(local[0].(P)() == 5)
}