hexops / valast

Convert Go values to their AST
Other
308 stars 16 forks source link

Bug: Stringifying a struct which contains a pointer to integer yields incorrect results. #15

Closed fkautz closed 2 years ago

fkautz commented 3 years ago

Stringifying a pointer to integer in a struct yields incorrect results. Here is an example for int64.

simple use case works

    i64 := int64(3607)
    test_str := String(&i64)

yields

valast.Addr(int64(3607)).(*int64)

nested in struct results in invalid output

    i64 := int64(3607)
    got := str{
        ExpirationSeconds: &i64,
    }

    test_str := String(got)

yields

valast.str{ExpirationSeconds: valast.Addr(3607).(*int64)}

This breaks for other integer types too.

slimsag commented 3 years ago

Hi there!

Thanks for reporting this; I'll see if I can investigate what is causing that in the next few weeks. If you want to send a PR (or even just a test case), please feel free to :)

slimsag commented 3 years ago

valast.str

It's odd it prefixes that type with valast. - I find that really surprising.