On Sat, 31 Aug 2024 at 14:22, Mike Schinkel <m...@newclarity.net> wrote:
> Hi Alex & Peter, > > Thank you both for your replies. > > On Aug 30, 2024, at 2:43 AM, Axel Wagner <axel.wagner...@googlemail.com> > wrote: > I don't think that error message comes from gofmt. As far as I am aware, > gofmt only parses source code, it does not even do type-checking. > > > As you sure about that? Running this: > > go fmt ./tools.go > > Generates this error for me using go1.23.0 (vs. go1.22.x): > > tools.go:9:2: import " > github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen" is a program, > not an importable package > You are right, I can reproduce that. As Jan, I was using `gofmt`, not `go fmt`. That's interesting. It seems the main difference is that `go fmt` accepts packages (and so it actually does have to look at import paths to a degree at least) while `gofmt` accepts files. Good to know. I think it probably shouldn't actually check the imports beyond finding the package you want to format. Perhaps that can be fixed. > > FWIW you might be interested in https://github.com/golang/go/issues/48429, > which gives a less hacky way to track tool dependencies and which (as far > as I know) has been accepted and is being implemented, with some delays due > to team changes. So, for the concrete issue, a solution is already being > worked on. > > > Thank you for that link. I will look into that for longer term. > > Shorter term, though it would be nice to find a way to resolve this. > Perhaps you can get your editor to run `gofmt` instead of `go fmt`? I'm sceptical that there will be a shorter-term way to change anything on the Go side - if this ends up being considered an issue to fix, it would only get fixed in Go 1.24 at the earliest. And I would kind of hope that, until then, #48429 is merged. > > On Aug 30, 2024, at 9:14 AM, peterGo <go.peter...@gmail.com> wrote: > Let's use official Go sources. > > go/src/cmd/tools/tools.go: > > Indent the tools.go import statement by a tab to force a reformat. > > $ go fmt > tools.go > $ > > Attempt to build package tools. > > $ go build > package cmd/tools: build constraints exclude all Go files in > /home/peter/go/src/cmd/tools > $ go build -tags=tools > tools.go:11:8: import "golang.org/x/tools/cmd/bisect" is a program, not > an importable package > $ > > Looks like a go build generated error. > > > Have you tried `go fmt` on `tools.go` with go1.23? > > I tried with go1.22.6 just now and it did not generate an error, but it > does with go1.23.0. > > -Mke > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfE%2BrrxKMGujGe16W%2BAcc5cDvFfCVQEr8Hq54gRmJZin4A%40mail.gmail.com.