ugorji / go

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

Incorrect codecgen code is generated #372

Closed mxmauro closed 1 year ago

mxmauro commented 2 years ago

Hi, I attached a sample project in order to show the issue.

The problem appears when a package tries to use code generated in other package.

To reproduce the issue follow this steps:

  1. Run go mod tidy and go mod vendor to download the dependencies. (vendoring is not required but used here to encapsulate the test)
  2. Run codecgen -nx -o test2_codec.go test2.go in the test2 subdirectory.
  3. Run codecgen -nx -o test_codec.go test.go in the "root" directory.
  4. Run go test

You will get something like this:

# test.com/test
.\test_codec.go:77:11: yysf5.CodecEncodeSelf undefined (type **test2.A has no field or method CodecEncodeSelf)
.\test_codec.go:101:11: yysf7.CodecEncodeSelf undefined (type **test2.A has no field or method CodecEncodeSelf)
.\test_codec.go:227:12: yysf4.CodecEncodeSelf undefined (type **test2.A has no field or method CodecEncodeSelf)
.\test_codec.go:254:12: yysf5.CodecEncodeSelf undefined (type **test2.A has no field or method CodecEncodeSelf)
FAIL    test.com/test [build failed]

I was able to patch it by replacing this line:

if ti2.flagSelfer {

with:

if ti2.flagSelfer || (isptr && ti2.flagSelferPtr) {

but not sure if the right thing to do.

Kind regards, Mauro.

mxmauro commented 2 years ago

Uploaded test to my github repo.

ugorji commented 1 year ago

Thanks so much for catching this. Your intuition was spot on. Fixed, and it will push it soon.

mxmauro commented 1 year ago

Excellent. I have other fixes to tell you but give me some time to create them (because Holidays). For e.g., this the attached code image

When zerocopy is active, no idea why a [32]byte object and a type Address [32]byte generates different flows and one of them leaves the array with zeroes.