-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.1.2
-
Component/s: BSON
-
Labels:None
-
Environment:go 1.13, linux
Can't marshal/unmarshal inline structs that are under the pointer
Example:
```golang
package foobar
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"log"
"testing"
"time"
)
type MContainer struct
{ M int `bson:"m,omitempty"` }type FoobarWithPointer struct
{ *MContainer `bson:",inline"` A int }type FoobarPointerless struct
{ MContainer `bson:",inline"` A int }func TestSandbox(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, _ := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
collection := client.Database("testing").Collection("numbers")
_, err := collection.InsertOne(ctx, &FoobarPointerless{A: 1, MContainer: MContainer{M: 10}})
log.Printf("pointerless: err = %s", err) // nil
_, err = collection.InsertOne(ctx, &FoobarWithPointer{A: 1, MContainer: &MContainer{M: 10}})
log.Printf("with pointer: err = %s", err) // cannot transform type *foobar.FoobarWithPointer to a BSON Document: (struct foobar.FoobarWithPointer) inline fields must be either a struct or a map
}
```