From a21f9ddfd05c643049c22bb52ab3a60f41933492 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 26 Nov 2025 21:04:12 -0500 Subject: Bugfix for accidental violation of immutable value guarantees due to inner field members --- src/types.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/types.c') diff --git a/src/types.c b/src/types.c index edfee27d..4d15d493 100644 --- a/src/types.c +++ b/src/types.c @@ -249,6 +249,27 @@ PUREFUNC bool has_heap_memory(type_t *t) { } } +PUREFUNC bool has_refcounts(type_t *t) { + switch (t->tag) { + case ListType: return true; + case TableType: return true; + case OptionalType: return has_refcounts(Match(t, OptionalType)->type); + case StructType: { + for (arg_t *field = Match(t, StructType)->fields; field; field = field->next) { + if (has_refcounts(field->type)) return true; + } + return false; + } + case EnumType: { + for (tag_t *tag = Match(t, EnumType)->tags; tag; tag = tag->next) { + if (tag->type && has_refcounts(tag->type)) return true; + } + return false; + } + default: return false; + } +} + PUREFUNC bool has_stack_memory(type_t *t) { if (!t) return false; switch (t->tag) { -- cgit v1.2.3