int32 is converted to int64 after incrementing

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Gone away
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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

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

            Assignee:
            Benji Rewis (Inactive)
            Reporter:
            Pierre Depretz
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: