LastPossum / kamino

Golang library for clone things
MIT License
46 stars 1 forks source link

Circular slices and maps threatment #2

Open LastPossum opened 1 year ago

LastPossum commented 1 year ago

For now, Kamino does not support circular slices and maps. Additionally, if two slices in the source object point to the same underlying array, this feature will not be kept in the copy object. Therefore, these cases will cause a stack overflow:

func TestCircularSlice(t *testing.T) {
    a := []any{nil}
    a[0] = a
    cp, err := kamino.Clone(a)

    assert.NoError(t, err)
    assert.Equal(t, cp, a)
}

func TestCircularMap(t *testing.T) {
    a := map[string]any{"a": nil}
    a["a"] = a
    cp, err := kamino.Clone(a)

    assert.NoError(t, err)
    assert.Equal(t, cp, a)
}