encode: fix embedded interfaces (#753)
Resolve marshaling regression when handling an embedded interface in a struct. Fixes #752
This commit is contained in:
@@ -600,7 +600,9 @@ func walkStruct(ctx encoderCtx, t *table, v reflect.Value) {
|
|||||||
|
|
||||||
if k == "" {
|
if k == "" {
|
||||||
if fieldType.Anonymous {
|
if fieldType.Anonymous {
|
||||||
|
if fieldType.Type.Kind() == reflect.Struct {
|
||||||
walkStruct(ctx, t, f)
|
walkStruct(ctx, t, f)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
k = fieldType.Name
|
k = fieldType.Name
|
||||||
|
|||||||
@@ -947,6 +947,22 @@ func TestIssue678(t *testing.T) {
|
|||||||
require.Equal(t, cfg, cfg2)
|
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) {
|
func TestMarshalNestedAnonymousStructs(t *testing.T) {
|
||||||
type Embedded struct {
|
type Embedded struct {
|
||||||
Value string `toml:"value" json:"value"`
|
Value string `toml:"value" json:"value"`
|
||||||
|
|||||||
Reference in New Issue
Block a user