From a5e80c75309277e0a215bc3d8f1345835d4dcbba Mon Sep 17 00:00:00 2001 From: Fernando Nunes Date: Fri, 25 Sep 2026 07:45:33 -0300 Subject: [PATCH] fix(checker): record instantiated poly proc on selector when used as a proc value --- src/check_expr.cpp | 7 ++++++- tests/issues/run.bat | 1 + tests/issues/run.sh | 1 + tests/issues/test_issue_7482.odin | 21 +++++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/issues/test_issue_7482.odin diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 1a4229475..758d7a5fd 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -951,7 +951,12 @@ gb_internal i64 check_distance_between_types(CheckerContext *c, Operand *operand if (check_polymorphic_procedure_assignment(c, operand, type, operand->expr, &poly_proc_data)) { Entity *e = poly_proc_data.gen_entity; add_type_and_value(c, operand->expr, Addressing_Value, e->type, {}); - add_entity_use(c, operand->expr, e); + Ast *expr = unparen_expr(operand->expr); + if (expr->kind == Ast_SelectorExpr) { + add_entity_use(c, expr->SelectorExpr.selector, e); + } else { + add_entity_use(c, operand->expr, e); + } return 4; } diff --git a/tests/issues/run.bat b/tests/issues/run.bat index 6f4c05c13..0a3127946 100644 --- a/tests/issues/run.bat +++ b/tests/issues/run.bat @@ -58,6 +58,7 @@ clang -c ..\test_issue_sysv_abi.c -o test_issue_sysv_abi_c.o || exit /b ..\..\..\odin test ..\test_issue_sysv_abi.odin %COMMON% || exit /b ..\..\..\odin build ..\test_issue_7073-1.odin %COMMON% 2>&1 | find /c "Error:" | findstr /x "2" || exit /b ..\..\..\odin test ..\test_issue_swizzle_multi_assign.odin %COMMON% || 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 diff --git a/tests/issues/run.sh b/tests/issues/run.sh index 7cd74fcda..08d2db369 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -90,6 +90,7 @@ $ODIN check ../test_issue_6979.odin -no-entry-point $COMMON_CHECK $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_7482.odin $COMMON $ODIN run ../test_issue_7564.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 diff --git a/tests/issues/test_issue_7482.odin b/tests/issues/test_issue_7482.odin new file mode 100644 index 000000000..7fac58617 --- /dev/null +++ b/tests/issues/test_issue_7482.odin @@ -0,0 +1,21 @@ +// Tests issue #7482 and #7474: a polymorphic procedure from another package used as a +// procedure value crashed the backend with `addr.addr.value != nullptr`. +// https://github.com/odin-lang/Odin/issues/7482 +package test_issues + +import "core:sort" + +apply :: proc(how: proc(a: []int), what: []int) { + how(what) +} + +main :: proc() { + a := [3]int{3, 1, 2} + apply(sort.quick_sort, a[:]) + assert(a == {1, 2, 3}) + + b := [3]int{2, 3, 1} + f: proc(a: []int) = (sort.quick_sort) + f(b[:]) + assert(b == {1, 2, 3}) +}