From 1c6b3aceeedf458f77e1b06ffb069ee8a261a007 Mon Sep 17 00:00:00 2001 From: jaina heartles Date: Fri, 9 Dec 2022 22:32:34 -0800 Subject: [PATCH] Fix deserialization for default values --- src/util/serialize.zig | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/serialize.zig b/src/util/serialize.zig index b28eb93..bd2e2a4 100644 --- a/src/util/serialize.zig +++ b/src/util/serialize.zig @@ -349,10 +349,14 @@ pub fn DeserializerContext(comptime Result: type, comptime From: type, comptime any_missing = true; } } - if (any_missing) { - return if (any_explicit) error.MissingField else null; - } + if (any_missing and any_explicit) return error.MissingField; + if (!any_explicit) { + inline for (info.fields) |field, i| { + if (fields_alloced[i]) self.deserializeFree(allocator, @field(result, field.name)); + } + return null; + } return result; },