From f91fd928427d8fbb2eceded163354c4dd612dd99 Mon Sep 17 00:00:00 2001 From: Nikolay Hadzhiev Date: Mon, 27 Apr 2026 10:28:35 +0200 Subject: [PATCH] gh 6621 --- src/check_builtin.cpp | 8 ++++++++ tests/issues/run.sh | 6 ++++++ tests/issues/test_issue_6621.odin | 10 ++++++++++ 3 files changed, 24 insertions(+) create mode 100644 tests/issues/test_issue_6621.odin diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 0d185a99f..2e1b3788b 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -3066,6 +3066,14 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As // check_assignment(c, operand, nullptr, str_lit("argument of 'type_of'")); if (o.mode == Addressing_Invalid || o.mode == Addressing_Builtin) { + Entity *e = entity_of_node(expr); + if (e != nullptr && + e->state == EntityState_InProgress && + e->type == nullptr) { + gbString s = expr_to_string(expr); + error(expr, "Invalid cyclic type usage from 'type_of', got '%s'", s); + gb_string_free(s); + } return false; } if (o.type == nullptr || o.type == t_invalid || is_type_asm_proc(o.type)) { diff --git a/tests/issues/run.sh b/tests/issues/run.sh index 2787235cb..f630738f9 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -59,6 +59,12 @@ else echo "SUCCESSFUL 0/1" exit 1 fi +if [[ $($ODIN build ../test_issue_6621.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 1 ]] ; then + echo "SUCCESSFUL 1/1" +else + echo "SUCCESSFUL 0/1" + exit 1 +fi $ODIN test ../test_pr_6470.odin $COMMON if [[ $($ODIN test ../test_pr_6470.odin -define:TEST_EXPECT_FAILURE=true $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 1 ]] ; then echo "SUCCESSFUL 1/1" diff --git a/tests/issues/test_issue_6621.odin b/tests/issues/test_issue_6621.odin new file mode 100644 index 000000000..ca76b23d5 --- /dev/null +++ b/tests/issues/test_issue_6621.odin @@ -0,0 +1,10 @@ +// Tests issue #6621 https://github.com/odin-lang/Odin/issues/6621 +package test_issues + +t: struct { + next: ^type_of(t), +} + +main :: proc() { + _ = t +}