diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-11-26 21:04:12 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-11-26 21:04:12 -0500 |
| commit | a21f9ddfd05c643049c22bb52ab3a60f41933492 (patch) | |
| tree | 8a4e3967f9d8b7863c238a357eb47e978d3a8c41 /src/compile/enums.c | |
| parent | 14c8cf34dd75fcf49cc56025efa93dd32e1958fd (diff) | |
Bugfix for accidental violation of immutable value guarantees due to
inner field members
Diffstat (limited to 'src/compile/enums.c')
| -rw-r--r-- | src/compile/enums.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/compile/enums.c b/src/compile/enums.c index 31af96ad..56d6432a 100644 --- a/src/compile/enums.c +++ b/src/compile/enums.c @@ -157,10 +157,15 @@ Text_t compile_enum_field_access(env_t *env, ast_t *ast) { if (streq(f->field, tag->name)) { Text_t tag_name = namespace_name(e->env, e->env->namespace, Texts("tag$", tag->name)); if (tag->type != NULL && Match(tag->type, StructType)->fields) { + Text_t member = compile_maybe_incref( + env, + WrapAST(ast, InlineCCode, + .chunks = new (ast_list_t, WrapAST(ast, TextLiteral, Texts("_e.", tag->name))), + .type = tag->type), + tag->type); return Texts("({ ", compile_declaration(value_t, Text("_e")), " = ", compile_to_pointer_depth(env, f->fielded, 0, false), "; ", "_e.$tag == ", tag_name, " ? ", - promote_to_optional(tag->type, Texts("_e.", tag->name)), " : ", compile_none(tag->type), - "; })"); + promote_to_optional(tag->type, member), " : ", compile_none(tag->type), "; })"); } else if (fielded_t->tag == PointerType) { Text_t fielded = compile_to_pointer_depth(env, f->fielded, 1, false); return Texts("((", fielded, ")->$tag == ", tag_name, " ? OPTIONAL_EMPTY_STRUCT : NONE_EMPTY_STRUCT)"); |
