From c8cd8dd2db9a895091f5151d0831c46407025369 Mon Sep 17 00:00:00 2001 From: Leandro Libanio Date: Wed, 1 Apr 2026 12:39:48 -0300 Subject: [PATCH] allow in-progress union variants when validating union members Fixes: #5961 --- src/check_type.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/check_type.cpp b/src/check_type.cpp index 18cbb4900..b7ff56536 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -796,11 +796,19 @@ gb_internal void check_union_type(CheckerContext *ctx, Type *union_type, Ast *no if (t != nullptr && t != t_invalid) { bool ok = true; t = default_type(t); - if (is_type_untyped(t) || is_type_empty_union(t)) { + if (is_type_untyped(t)) { ok = false; gbString str = type_to_string(t); error(node, "Invalid variant type in union '%s'", str); gb_string_free(str); + } else if (is_type_empty_union(t)) { + Type *base = base_type(t); + if (base == nullptr || base->kind != Type_Union || base->Union.node == nullptr) { + ok = false; + gbString str = type_to_string(t); + error(node, "Invalid variant type in union '%s'", str); + gb_string_free(str); + } } else { for_array(j, variants) { if (union_variant_index_types_equal(t, variants[j])) {