diff --git a/client/normal_nil.go b/client/normal_nil.go index 7513fa9979..7cd2df3f16 100644 --- a/client/normal_nil.go +++ b/client/normal_nil.go @@ -34,14 +34,22 @@ func NewNormalNil(kind FieldKind) (NormalValue, error) { return NewNormalNillableString(immutable.None[string]()), nil case FieldKind_NILLABLE_BLOB: return NewNormalNillableBytes(immutable.None[[]byte]()), nil - case FieldKind_NILLABLE_BOOL_ARRAY: + case FieldKind_BOOL_ARRAY: return NewNormalBoolNillableArray(immutable.None[[]bool]()), nil - case FieldKind_NILLABLE_INT_ARRAY: + case FieldKind_INT_ARRAY: return NewNormalIntNillableArray(immutable.None[[]int64]()), nil - case FieldKind_NILLABLE_FLOAT_ARRAY: + case FieldKind_FLOAT_ARRAY: return NewNormalFloatNillableArray(immutable.None[[]float64]()), nil - case FieldKind_NILLABLE_STRING_ARRAY: + case FieldKind_STRING_ARRAY: return NewNormalStringNillableArray(immutable.None[[]string]()), nil + case FieldKind_NILLABLE_BOOL_ARRAY: + return NewNormalNillableBoolNillableArray(immutable.None[[]immutable.Option[bool]]()), nil + case FieldKind_NILLABLE_INT_ARRAY: + return NewNormalNillableIntNillableArray(immutable.None[[]immutable.Option[int]]()), nil + case FieldKind_NILLABLE_FLOAT_ARRAY: + return NewNormalNillableFloatNillableArray(immutable.None[[]immutable.Option[float64]]()), nil + case FieldKind_NILLABLE_STRING_ARRAY: + return NewNormalNillableStringNillableArray(immutable.None[[]immutable.Option[string]]()), nil default: return nil, NewCanNotMakeNormalNilFromFieldKind(kind) } diff --git a/client/normal_value_test.go b/client/normal_value_test.go index 75e858b056..33cd20c46e 100644 --- a/client/normal_value_test.go +++ b/client/normal_value_test.go @@ -1622,3 +1622,28 @@ func TestNormalValue_ToArrayOfNormalValues(t *testing.T) { }) } } + +// This test documents a bug where array values +// were not returning the correct value for IsNillable +// and were also not convertible to a normal nil kind. +func TestArrayValue_IsNillable(t *testing.T) { + fieldKinds := []FieldKind{ + FieldKind_BOOL_ARRAY, + FieldKind_INT_ARRAY, + FieldKind_FLOAT_ARRAY, + FieldKind_STRING_ARRAY, + FieldKind_NILLABLE_BOOL_ARRAY, + FieldKind_NILLABLE_INT_ARRAY, + FieldKind_NILLABLE_FLOAT_ARRAY, + FieldKind_NILLABLE_STRING_ARRAY, + } + + for _, kind := range fieldKinds { + assert.True(t, kind.IsNillable()) + + v, err := NewNormalNil(kind) + require.NoError(t, err) + + assert.True(t, v.IsNil()) + } +} diff --git a/client/schema_field_description.go b/client/schema_field_description.go index f317ace116..87ee843ec8 100644 --- a/client/schema_field_description.go +++ b/client/schema_field_description.go @@ -147,10 +147,7 @@ func (k ScalarArrayKind) Underlying() string { } func (k ScalarArrayKind) IsNillable() bool { - return k == FieldKind_NILLABLE_BOOL_ARRAY || - k == FieldKind_NILLABLE_INT_ARRAY || - k == FieldKind_NILLABLE_FLOAT_ARRAY || - k == FieldKind_NILLABLE_STRING_ARRAY + return true } func (k ScalarArrayKind) IsObject() bool {