diff --git a/src/checker.cpp b/src/checker.cpp index f9e1f523f..fa65098a8 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -2153,7 +2153,9 @@ gb_internal void add_entity_use(CheckerContext *c, Ast *identifier, Entity *enti if (identifier == nullptr || identifier->kind != Ast_Ident) { return; } - entity->identifier.store(identifier); + // NOTE: only set it once, as `$` procedure arguments are matched by this identifier + Ast *empty_ident = nullptr; + entity->identifier.compare_exchange_strong(empty_ident, identifier); identifier->Ident.entity = entity; diff --git a/tests/issues/run.bat b/tests/issues/run.bat index db165a28e..21286575a 100644 --- a/tests/issues/run.bat +++ b/tests/issues/run.bat @@ -46,6 +46,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused ..\..\..\odin test ..\test_issue_bool_comparison_truthiness.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_const_array_broadcast.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_forwarded_poly_proc.odin %COMMON% || exit /b +..\..\..\odin test ..\test_issue_proc_constant_instantiation.odin %COMMON% || exit /b ..\..\..\odin check ..\test_issue_7336.odin -no-entry-point %COMMON% || exit /b ..\..\..\odin check ..\test_issue_ellipsis_type_call.odin -no-entry-point %COMMON% 2>&1 | find /c "Error:" | findstr /x "10" || exit /b ..\..\..\odin check ..\test_issue_foreign_redeclaration.odin -no-entry-point %COMMON% || exit /b diff --git a/tests/issues/run.sh b/tests/issues/run.sh index a528fa5df..0d049886e 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -109,6 +109,7 @@ $ODIN test ../test_issue_bool_to_be_conversion.odin $COMMON $ODIN test ../test_issue_bool_comparison_truthiness.odin $COMMON $ODIN test ../test_issue_const_array_broadcast.odin $COMMON $ODIN test ../test_issue_forwarded_poly_proc.odin $COMMON +$ODIN test ../test_issue_proc_constant_instantiation.odin $COMMON $ODIN test ../test_issue_swizzle_multi_assign.odin $COMMON $ODIN check ../test_issue_foreign_redeclaration.odin -no-entry-point $COMMON_CHECK diff --git a/tests/issues/test_issue_proc_constant_instantiation.odin b/tests/issues/test_issue_proc_constant_instantiation.odin new file mode 100644 index 000000000..718f6d06b --- /dev/null +++ b/tests/issues/test_issue_proc_constant_instantiation.odin @@ -0,0 +1,17 @@ +package test_issues + +import "core:testing" + +// Passing the same procedure to a `$` parameter from two calls used to generate two instantiations, +// each with its own `Box` crashing the compiler. + +box_of :: proc($f: proc() -> int) -> typeid { + Box :: struct {} + return Box +} +one :: proc() -> int { return 1 } + +@(test) +proc_constant_instantiation :: proc(t: ^testing.T) { + testing.expect_value(t, box_of(one), box_of(one)) +}