Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2451

int32 is converted to int64 after incrementing

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Gone away
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Summary

      A user is trying to use the $inc operator to increment by a small number (uint32) an int32 type. This operation makes the field be converted into int64. This snippet should return an int32 as mentioned in the comment ("If ec.MinSize or if encodeToMinSize is true for a non-uint64 value we should write val as an int32") but since useMinSize is false in his case, an int64 is returned. 

      Therefore the main question is, how to force useMinSize to true?

      It's also worth noting that:

      • EncodeToMinSize returns false in his case despite no custom codec (uintcodec)
      • Therefore he uses the default encoder (defaultUIntCodec) here
      • Default encoder is created here ... which does not pass in any options so EncodeToMinSize gets the Golang zero value for bool which is false.

      How to Reproduce

      User images are attached

      Attachments

        1. image+(3).png
          image+(3).png
          17 kB
        2. image+(4).png
          image+(4).png
          17 kB
        3. image+(5).png
          image+(5).png
          98 kB
        4. image+(6).png
          image+(6).png
          40 kB
        5. image+(7).png
          image+(7).png
          89 kB
        6. image+(8).png
          image+(8).png
          121 kB
        7. increment.go
          2 kB

        Activity

          People

            benji.rewis@mongodb.com Benji Rewis (Inactive)
            pierre.depretz@mongodb.com Pierre Depretz
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: