garble icon indicating copy to clipboard operation
garble copied to clipboard

fail to build # github.com/go-json-experiment/json

Open PhracturedBlue opened this issue 9 months ago • 4 comments

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.

PhracturedBlue avatar Mar 01 '25 14:03 PhracturedBlue

Did you find a fix?

jxhn0 avatar Apr 06 '25 23:04 jxhn0

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.

mvdan avatar Apr 20 '25 22:04 mvdan

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.

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 =.

phusinhngay2011 avatar May 09 '25 11:05 phusinhngay2011

I also got this but I have no idea how to locate the original code.

DefinitlyEvil avatar Oct 05 '25 12:10 DefinitlyEvil