diff --git a/compiler/cbuilderdecls.nim b/compiler/cbuilderdecls.nim index 74ed391431ec..e5032d743116 100644 --- a/compiler/cbuilderdecls.nim +++ b/compiler/cbuilderdecls.nim @@ -68,7 +68,7 @@ type siOrderedStruct ## struct constructor, but without named fields on C siNamedStruct ## struct constructor, with named fields i.e. C99 designated initializer siArray ## array constructor - siWrapper ## wrapper for a single field, generates it verbatim, now unused + siWrapper ## wrapper for a single field, generates it verbatim StructInitializer = object ## context for building struct initializers, i.e. `{ field1, field2 }` diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 42b953fd7e3b..0b4073f6b37e 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -3306,7 +3306,11 @@ proc getNullValueAux(p: BProc; t: PType; obj, constOrNil: PNode, var branchInit: StructInitializer result.addStructInitializer(branchInit, kind = siNamedStruct): result.addField(branchInit, name = fieldName): - getNullValueAux(p, t, b, constOrNil, result, branchInit, isConst, info) + # we need to generate the default value of the single sym, + # to do this create a dummy wrapper initializer and recurse + var branchFieldInit: StructInitializer + result.addStructInitializer(branchFieldInit, kind = siWrapper): + getNullValueAux(p, t, b, constOrNil, result, branchFieldInit, isConst, info) else: # no fields, don't initialize return