diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-09-29 13:12:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-29 13:12:07 +0100 |
| commit | 11dc6680d2101a76e5fff8baedd8717501b625c0 (patch) | |
| tree | cc80ffec2742974e4e4882eb209e03248410adbe /src/check_decl.cpp | |
| parent | d3b877031838c5a13c4adbfdd1d8fb77c35c9801 (diff) | |
| parent | 240b2f1819294cc59b48f88ef3344bf77265fec6 (diff) | |
Merge pull request #5723 from odin-lang/bill/const-union
Basic support for constant union literals
Diffstat (limited to 'src/check_decl.cpp')
| -rw-r--r-- | src/check_decl.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp index bda1059fb..842f8653c 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -1686,7 +1686,28 @@ gb_internal void check_global_variable_decl(CheckerContext *ctx, Entity *e, Ast check_expr_with_type_hint(ctx, &o, init_expr, e->type); check_init_variable(ctx, e, &o, str_lit("variable declaration")); if (e->Variable.is_rodata && o.mode != Addressing_Constant) { + ERROR_BLOCK(); error(o.expr, "Variables declared with @(rodata) must have constant initialization"); + Ast *expr = unparen_expr(o.expr); + if (is_type_struct(e->type) && expr && expr->kind == Ast_CompoundLit) { + ast_node(cl, CompoundLit, expr); + for (Ast *elem_ : cl->elems) { + Ast *elem = elem_; + if (elem->kind == Ast_FieldValue) { + elem = elem->FieldValue.value; + } + elem = unparen_expr(elem); + + Entity *e = entity_of_node(elem); + if (elem->tav.mode != Addressing_Constant && e == nullptr && elem->kind != Ast_ProcLit) { + Token tok = ast_token(elem); + TokenPos pos = tok.pos; + gbString s = type_to_string(type_of_expr(elem)); + error_line("%s Element is not constant, which is required for @(rodata), of type %s\n", token_pos_to_string(pos), s); + gb_string_free(s); + } + } + } } check_rtti_type_disallowed(e->token, e->type, "A variable declaration is using a type, %s, which has been disallowed"); |