encoder: inline tables create map in nil interface (#496)

Co-authored-by: Thomas Pelletier <pelletier.thomas@gmail.com>
This commit is contained in:
Cameron Moore
2021-04-09 08:02:00 -05:00
committed by GitHub
parent e1f035461b
commit 466bfe8664
3 changed files with 35 additions and 6 deletions
+3 -5
View File
@@ -120,11 +120,7 @@ func (d *decoder) fromParser(p *parser, v interface{}) error {
// looks like a table. Otherwise the information
// of a table is lost, and marshal cannot do the
// round trip.
v := current.get()
if v.Kind() == reflect.Interface && v.IsNil() {
newElement := reflect.MakeMap(mapStringInterfaceType)
current.set(newElement)
}
ensureMapIfInterface(current)
}
case ast.ArrayTable:
current, found, err = d.scopeWithArrayTable(root, node.Key())
@@ -381,6 +377,8 @@ func unmarshalFloat(x target, node ast.Node) error {
func (d *decoder) unmarshalInlineTable(x target, node ast.Node) error {
assertNode(ast.InlineTable, node)
ensureMapIfInterface(x)
it := node.Children()
for it.Next() {
n := it.Node()