From bafff9429ebe8641aedbbc5d8458ea3db40b2190 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Wed, 30 Oct 2024 13:18:35 +0000 Subject: [PATCH] Hmm --- encode.go | 18 +++++++++--------- encode_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/encode.go b/encode.go index bde6535..8e19ffe 100644 --- a/encode.go +++ b/encode.go @@ -476,15 +476,15 @@ func (enc *Encoder) eStruct(key Key, rv reflect.Value, inline bool) { frv := eindirect(rv.Field(i)) - if is32Bit { - // Copy so it works correct on 32bit archs; not clear why this - // is needed. See #314, and https://www.reddit.com/r/golang/comments/pnx8v4 - // This also works fine on 64bit, but 32bit archs are somewhat - // rare and this is a wee bit faster. - copyStart := make([]int, len(start)) - copy(copyStart, start) - start = copyStart - } + //if is32Bit { + // Copy so it works correct on 32bit archs; not clear why this + // is needed. See #314, and https://www.reddit.com/r/golang/comments/pnx8v4 + // This also works fine on 64bit, but 32bit archs are somewhat + // rare and this is a wee bit faster. + copyStart := make([]int, len(start)) + copy(copyStart, start) + start = copyStart + //} // Treat anonymous struct fields with tag names as though they are // not anonymous, like encoding/json does. diff --git a/encode_test.go b/encode_test.go index a5c3a7e..8a7e3d4 100644 --- a/encode_test.go +++ b/encode_test.go @@ -836,6 +836,17 @@ func TestEncodeJSONNumber(t *testing.T) { } } +type ( + StructA struct{ StructB } + StructB struct{ StructC } + StructC struct{ StructD } + StructD struct { + FieldD1 string + FieldD2 string + FieldD3 string + } +) + func TestEncode(t *testing.T) { type ( Embedded struct { @@ -1114,6 +1125,20 @@ ArrayOfMixedSlices = [[1, 2], ["a", "b"]] }{struct{ Embedded }{Embedded{1}}}, wantOutput: "[_struct]\n _int = 1\n", }, + "deeply nested embedded struct": { // #430 + input: StructA{ + StructB: StructB{ + StructC: StructC{ + StructD: StructD{ + FieldD1: "V1", + FieldD2: "V2", + FieldD3: "V3", + }, + }, + }, + }, + wantOutput: "FieldD1 = \"V1\"\nFieldD2 = \"V2\"\nFieldD3 = \"V3\"\n", + }, "nested embedded *struct": { input: struct { Struct struct{ *Embedded } `toml:"_struct"`