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

Allowing pointer of type to implement an interface causes errors for non-addressable types

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 1.3.3
    • None
    • None
    • None

    Description

      In GODRIVER-1356, we allowed a pointer to a type to implement the hooks we check for during BSON encoding/decoding (e.g. bsoncodec.Marshaler). This causes problems if the value being marshalled isn't addressable but a pointer to the value implements the hook. The registry will return the codec for the hook, but the codec will error because val.CanAddr returns false. See https://play.golang.org/p/GwmqXl5sFAx for a repro.

      As a side-note, I don't really understand why the value isn't addressable. Unfortunately, the registry does lookups using reflect.Type so it doesn't have enough information to know if the value is addressable or not.

      Attachments

        Activity

          People

            isabella.siu@mongodb.com Isabella Siu (Inactive)
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: