rillig / gobco

Measure branch coverage of golang tests
62 stars 12 forks source link

fmt.Sprint(func) does not compile #36

Open cphaensch opened 2 months ago

cphaensch commented 2 months ago
./packrat.go:361:43: fmt.Sprint arg List is a func value, not called
./printer.go:66:23: fmt.Sprint arg v is a func value, not called
./printer.go:66:40: fmt.Sprint arg List is a func value, not called
./printer.go:142:119: fmt.Sprint arg List is a func value, not called
./printer.go:165:25: fmt.Sprint arg v is a func value, not called

The thing is, the code is correct and should compile (and does compile on go 1.22.0). The result of fmt.Sprint(f) where f is a func() is a hex value identifying the closure like in:

                // tell if v is the "List" function
                if fmt.Sprint(v) == fmt.Sprint(List) { //fmt.Sprint
                        return "list"
                }
rillig commented 2 months ago

If your code does not build successfully, it is not ready for gobco.

Just as you need to run go test -vet=off for your code to build, you need to run gobco -test -vet=off to run gobco on it.

I don't see anything that gobco should do differently to support your case.

cphaensch commented 2 months ago

The code builds with Go 1.22.0, but does not build with goboco.

I changed the code from fmt.Sprint(f) to reflect.GetValue(f).Pointer() though, so it works now ;)

rillig commented 1 month ago

Sorry for prematurely closing this issue, now I understand it. I'll have to look into the details why gobco fails but a plain go test succeeds.