From b1914fc217b58b048b410b71f60ceb635ea32fb4 Mon Sep 17 00:00:00 2001 From: Larsimusrex Date: Fri, 12 Sep 2025 11:21:02 +0200 Subject: [PATCH] fix type_default for empty structs --- vlib/v/gen/c/cgen.v | 3 ++- vlib/x/json2/types.v | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index e3931558a3..c4fece7672 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -7574,8 +7574,9 @@ fn (mut g Gen) type_default_impl(typ_ ast.Type, decode_sumtype bool) string { } } .struct { - mut has_none_zero := false info := sym.info as ast.Struct + mut has_none_zero := info.fields.len == 0 + mut init_str := if info.is_anon && !g.inside_global_decl { '(${g.styp(typ)}){' } else { diff --git a/vlib/x/json2/types.v b/vlib/x/json2/types.v index b9a71fd5b6..e600686701 100644 --- a/vlib/x/json2/types.v +++ b/vlib/x/json2/types.v @@ -24,9 +24,7 @@ pub type Any = []Any | Null // Null is a simple representation of the `null` value in JSON. -pub struct Null { - is_null bool = true -} +pub struct Null {} // null is an instance of the Null type, to ease comparisons with it. pub const null = Null{}