ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.86k stars 295 forks source link

codecgen: non-compilable code for embedded fields with overlapping names #297

Closed zeldovich closed 5 years ago

zeldovich commented 5 years ago
% cat bug1.go
package xx

type A struct {
        A int
}

type B struct {
        A
}
% ~/go/bin/codecgen -o gen.go bug1.go
% go build bug1.go gen.go
# command-line-arguments
./gen.go:214:23: cannot convert x.A (type A) to type int64
./gen.go:226:23: cannot convert x.A (type A) to type int64
./gen.go:290:9: cannot use int(z.C.IntV(r.decDriver.DecodeInt64(), codecSelferBitsize8365)) (type int) as type A in assignment
./gen.go:320:7: cannot use int(z.C.IntV(r.decDriver.DecodeInt64(), codecSelferBitsize8365)) (type int) as type A in assignment
% 

and:

% cat bug2.go
package xx

type P struct {
        X int
}

type Q struct {
        X int
}

type Z struct {
        P
        Q
}
% ~/go/bin/codecgen -o gen.go bug2.go
% go build bug2.go gen.go
# command-line-arguments
./gen.go:362:25: ambiguous selector x.X
./gen.go:374:25: ambiguous selector x.X
./gen.go:381:25: ambiguous selector x.X
./gen.go:393:25: ambiguous selector x.X
./gen.go:457:6: ambiguous selector x.X
% 
ugorji commented 5 years ago

Is this supported by go?

zeldovich commented 5 years ago

Is this supported by go?

Yes:

% go build bug1.go bug2.go 
% 
zeldovich commented 5 years ago

The bug2.go file from my initial bug report still fails (though for a different reason now):

% cat bug2.go
package xx

type P struct {
        X int
}

type Q struct {
        X int
}

type Z struct {
        P
        Q
}
% ~/go/bin/codecgen -o gen.go bug2.go
% go build bug2.go gen.go
# command-line-arguments
./gen.go:461:3: duplicate case "X" in switch
        previous case at ./gen.go:455:8
%
ugorji commented 5 years ago

In your opinion, what should "X" in the encoded stream map to? Z.P.X or Z.Q.X?