From d39fe1685b7002cd239732fbdfca4bcba1934f83 Mon Sep 17 00:00:00 2001 From: Paul Hatchman Date: Sat, 6 Dec 2025 11:02:17 +1100 Subject: [PATCH] struct_ui: Change missing default value to runtime error. - Previously any optional struct that could not be initialized due to a missing default value would be a compile time error. - This is not a runtime error with a debug message logged and the optional remaining as null --- src/struct_ui.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/struct_ui.zig b/src/struct_ui.zig index c316d0cd..53047193 100644 --- a/src/struct_ui.zig +++ b/src/struct_ui.zig @@ -903,7 +903,7 @@ fn canDisplayPtr(ptr: std.builtin.Type.Pointer) bool { /// NOTE: /// Any modified text fields are dynamically allocated. These are cleaned up during Window.deinit() /// If a string should not be automatically cleaned up (i.e will be cleaned up by a struct's deinit() method), -/// removed the string from struct_ui.string map prior to the Window.deinit() being called. +/// remove the string from struct_ui.string map prior to the Window.deinit() being called. /// /// The displayStringBuf() function can be used as an alternative to display strings with a user-supplied buffer. pub fn displayStruct( @@ -990,7 +990,8 @@ pub fn defaultValue(T: type, struct_options: anytype) ?T { if (!default_found) { inline for (si.fields) |field| { if (field.defaultValue() == null) { - @compileError(std.fmt.comptimePrint("field {s} for struct {s} does not support default initialization", .{ field.name, @typeName(T) })); + // The struct can't be default initialized and no struct_options were supplied for this type. + return null; } } } -- knotmirror 0.0.1