fail to build # github.com/go-json-experiment/json
When trying to build go-json-experiment/json, I get an error:
# github.com/go-json-experiment/json
IuxlaZvuzqM.go:8: unknown field pbs6TV9wghYE in struct literal of type PKGMB0A
zBJu2p.go:9: unknown field pbs6TV9wghYE in struct literal of type PKGMB0A
sLSdey.go:6: unknown field rG6shOjqY in struct literal of type FqxD7Z9Mz
MV08EKSa.go:9: unknown field rG6shOjqY in struct literal of type FqxD7Z9Mz
exit status 2
exit status 1
This can be easily reproduced with one of the examples like: https://pkg.go.dev/github.com/go-json-experiment/json#example-package-FieldNames
Unfortunately this is embedded with another library I use, so I don't have the ability to use an alternate json library.
Did you find a fix?
Reduced to the following; it seems related to type aliases combined with generic types.
package main
func main() {
var ga genericAlias
ga.list = nil
var gan genericAliasNamed
gan.list = nil
}
type genericAlias = generic[int]
type generic[T any] struct {
list *T
}
type genericAliasNamed genericAlias
$ go build .; echo; garble build -a .
# test
:7: f8ijZvS.oktW6muk undefined (type k9uaLgEqw has no field or method oktW6muk)
:9: i8xkqEXk.oktW6muk undefined (type iNhgLpYrqib has no field or method oktW6muk)
exit status 2
exit status 1
What's weirder is that garble build . without -a sometimes succeeds. Which seems to suggest that there's some sort of caching bug happening here.
Reduced to the following; it seems related to type aliases combined with generic types.
package main func main() { var ga genericAlias ga.list = nil var gan genericAliasNamed gan.list = nil } type genericAlias = generic[int] type generic[T any] struct { list *T } type genericAliasNamed genericAlias$ go build .; echo; garble build -a . # test :7: f8ijZvS.oktW6muk undefined (type k9uaLgEqw has no field or method oktW6muk) :9: i8xkqEXk.oktW6muk undefined (type iNhgLpYrqib has no field or method oktW6muk) exit status 2 exit status 1What's weirder is that
garble build .without-asometimes succeeds. Which seems to suggest that there's some sort of caching bug happening here.
The cause is here: type genericAliasNamed genericAlias. type T T0 will declare declares a new type exactly like T0. But type T = T0 is an alias declaration.
For example, if you use type T T0, garble will hash T0 to ABC1, but T will be something like DFE.
So, just add =.
I also got this but I have no idea how to locate the original code.