diff --git a/core/memstore/memstore.go b/core/memstore/memstore.go index bc01fb0a..53946673 100644 --- a/core/memstore/memstore.go +++ b/core/memstore/memstore.go @@ -173,6 +173,7 @@ func (e Entry) IntDefault(def int) (int, error) { return int(vv), nil case int64: return int(vv), nil + case uint: return int(vv), nil case uint8: @@ -213,6 +214,17 @@ func (e Entry) Int8Default(def int8) (int8, error) { return int8(vv), nil case int64: return int8(vv), nil + + case uint: + return int8(vv), nil + case uint8: + return int8(vv), nil + case uint16: + return int8(vv), nil + case uint32: + return int8(vv), nil + case uint64: + return int8(vv), nil } return def, e.notFound(reflect.Int8) @@ -243,6 +255,17 @@ func (e Entry) Int16Default(def int16) (int16, error) { return int16(vv), nil case int64: return int16(vv), nil + + case uint: + return int16(vv), nil + case uint8: + return int16(vv), nil + case uint16: + return int16(vv), nil + case uint32: + return int16(vv), nil + case uint64: + return int16(vv), nil } return def, e.notFound(reflect.Int16) @@ -297,6 +320,17 @@ func (e Entry) Int64Default(def int64) (int64, error) { return int64(vv), nil case int: return int64(vv), nil + + case uint: + return int64(vv), nil + case uint8: + return int64(vv), nil + case uint16: + return int64(vv), nil + case uint32: + return int64(vv), nil + case uint64: + return int64(vv), nil } return def, e.notFound(reflect.Int64) @@ -344,6 +378,14 @@ func (e Entry) UintDefault(def uint) (uint, error) { return def, e.notFound(reflect.Uint) } return uint(vv), nil + case int8: + return uint(vv), nil + case int16: + return uint(vv), nil + case int32: + return uint(vv), nil + case int64: + return uint(vv), nil } return def, e.notFound(reflect.Uint) diff --git a/core/memstore/memstore_test.go b/core/memstore/memstore_test.go index bec4ec23..91233c05 100644 --- a/core/memstore/memstore_test.go +++ b/core/memstore/memstore_test.go @@ -110,3 +110,12 @@ func TestImmutableSetOnlyWithSetImmutable(t *testing.T) { t.Fatalf("caller should be able to change the immutable entry with a `SetImmutable`") } } + +func TestGetInt64Default(t *testing.T) { + var p Store + + p.Set("a uint16", uint16(2)) + if v := p.GetInt64Default("a uint16", 0); v != 2 { + t.Fatalf("unexpected value of %d", v) + } +}