diff --git a/ast/node.go b/ast/node.go index 4a155eb23..423b8ba81 100644 --- a/ast/node.go +++ b/ast/node.go @@ -534,10 +534,12 @@ func (self *Node) Set(key string, node Node) (bool, error) { if err := node.Check(); err != nil { return false, err } - + if self.t == _V_NONE || self.t == types.V_NULL { *self = NewObject([]Pair{{key, node}}) return false, nil + } else if self.itype() != types.V_OBJECT { + return false, ErrUnsupportType } p := self.Get(key) diff --git a/ast/node_test.go b/ast/node_test.go index 45a063679..8ab116692 100644 --- a/ast/node_test.go +++ b/ast/node_test.go @@ -1204,6 +1204,11 @@ func TestNodeGetByPath(t *testing.T) { } func TestNodeSet(t *testing.T) { + arr := NewRaw(`[]`) + ex, ee := arr.Set("a", NewNumber("-1")) + if ex || ee == nil { + t.Fatal() + } empty := Node{} err := empty.Add(Node{}) if err != nil {