diff --git a/bson/bsoncodec.go b/bson/bsoncodec.go index e0369a1111..08e3d4b862 100644 --- a/bson/bsoncodec.go +++ b/bson/bsoncodec.go @@ -171,8 +171,8 @@ type decodeAdapter struct { var _ ValueDecoder = decodeAdapter{} var _ typeDecoder = decodeAdapter{} -func decodeTypeOrValueWithInfo(vd ValueDecoder, td typeDecoder, dc DecodeContext, vr ValueReader, t reflect.Type, convert bool) (reflect.Value, error) { - if td != nil { +func decodeTypeOrValueWithInfo(vd ValueDecoder, dc DecodeContext, vr ValueReader, t reflect.Type, convert bool) (reflect.Value, error) { + if td := vd.(typeDecoder); td != nil { val, err := td.decodeType(dc, vr, t) if err == nil && convert && val.Type() != t { // This conversion step is necessary for slices and maps. If a user declares variables like: diff --git a/bson/default_value_decoders.go b/bson/default_value_decoders.go index 56331da9a8..50f7fc7cb9 100644 --- a/bson/default_value_decoders.go +++ b/bson/default_value_decoders.go @@ -135,7 +135,6 @@ func dDecodeValue(dc DecodeContext, vr ValueReader, val reflect.Value) error { if err != nil { return err } - tEmptyTypeDecoder, _ := decoder.(typeDecoder) // Use the elements in the provided value if it's non nil. Otherwise, allocate a new D instance. var elems D @@ -155,7 +154,7 @@ func dDecodeValue(dc DecodeContext, vr ValueReader, val reflect.Value) error { } // Pass false for convert because we don't need to call reflect.Value.Convert for tEmpty. - elem, err := decodeTypeOrValueWithInfo(decoder, tEmptyTypeDecoder, dc, elemVr, tEmpty, false) + elem, err := decodeTypeOrValueWithInfo(decoder, dc, elemVr, tEmpty, false) if err != nil { return err } @@ -1274,7 +1273,6 @@ func decodeDefault(dc DecodeContext, vr ValueReader, val reflect.Value) ([]refle if err != nil { return nil, err } - eTypeDecoder, _ := decoder.(typeDecoder) idx := 0 for { @@ -1286,7 +1284,7 @@ func decodeDefault(dc DecodeContext, vr ValueReader, val reflect.Value) ([]refle return nil, err } - elem, err := decodeTypeOrValueWithInfo(decoder, eTypeDecoder, dc, vr, eType, true) + elem, err := decodeTypeOrValueWithInfo(decoder, dc, vr, eType, true) if err != nil { return nil, newDecodeError(strconv.Itoa(idx), err) } diff --git a/bson/empty_interface_codec.go b/bson/empty_interface_codec.go index 59754ec6b5..b8314a873f 100644 --- a/bson/empty_interface_codec.go +++ b/bson/empty_interface_codec.go @@ -99,7 +99,7 @@ func (eic emptyInterfaceCodec) decodeType(dc DecodeContext, vr ValueReader, t re return emptyValue, err } - elem, err := decodeTypeOrValueWithInfo(decoder, decoder.(typeDecoder), dc, vr, rtype, true) + elem, err := decodeTypeOrValueWithInfo(decoder, dc, vr, rtype, true) if err != nil { return emptyValue, err } diff --git a/bson/map_codec.go b/bson/map_codec.go index bfa77ca0d8..5f6963ed26 100644 --- a/bson/map_codec.go +++ b/bson/map_codec.go @@ -160,7 +160,6 @@ func (mc *mapCodec) DecodeValue(dc DecodeContext, vr ValueReader, val reflect.Va if err != nil { return err } - eTypeDecoder, _ := decoder.(typeDecoder) if eType == tEmpty { dc.ancestor = val.Type() @@ -182,7 +181,7 @@ func (mc *mapCodec) DecodeValue(dc DecodeContext, vr ValueReader, val reflect.Va return err } - elem, err := decodeTypeOrValueWithInfo(decoder, eTypeDecoder, dc, vr, eType, true) + elem, err := decodeTypeOrValueWithInfo(decoder, dc, vr, eType, true) if err != nil { return newDecodeError(key, err) }