Skip to content

Commit

Permalink
Hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Oct 30, 2024
1 parent eb72747 commit bafff94
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
18 changes: 9 additions & 9 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit bafff94

Please sign in to comment.