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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3.3
    • Component/s: None
    • Labels:
      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

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

              Dates

              Created:
              Updated:
              Resolved: