Skip to content

Commit

Permalink
encode: fix embedded interfaces (#753)
Browse files Browse the repository at this point in the history
Resolve marshaling regression when handling an embedded interface in a
struct.

Fixes #752
  • Loading branch information
pelletier committed Apr 8, 2022
1 parent f5cc8c4 commit 2377ac4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion marshaler.go
Expand Up @@ -600,7 +600,9 @@ func walkStruct(ctx encoderCtx, t *table, v reflect.Value) {

if k == "" {
if fieldType.Anonymous {
walkStruct(ctx, t, f)
if fieldType.Type.Kind() == reflect.Struct {
walkStruct(ctx, t, f)
}
continue
} else {
k = fieldType.Name
Expand Down
16 changes: 16 additions & 0 deletions marshaler_test.go
Expand Up @@ -947,6 +947,22 @@ func TestIssue678(t *testing.T) {
require.Equal(t, cfg, cfg2)
}

func TestIssue752(t *testing.T) {
type Fooer interface {
Foo() string
}

type Container struct {
Fooer
}

c := Container{}

out, err := toml.Marshal(c)
require.NoError(t, err)
require.Equal(t, "", string(out))
}

func TestMarshalNestedAnonymousStructs(t *testing.T) {
type Embedded struct {
Value string `toml:"value" json:"value"`
Expand Down

0 comments on commit 2377ac4

Please sign in to comment.