> On Aug 31, 2024, at 9:45 AM, Axel Wagner <axel.wagner...@googlemail.com> > wrote: > > On Sat, 31 Aug 2024 at 14:22, Mike Schinkel <m...@newclarity.net > <mailto: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 >> <mailto: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 > <http://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.
Thank you for checking it. Sometimes an error in understand can reveal undiscovered bugs. Happy accidents. > Perhaps you can get your editor to run `gofmt` instead of `go fmt`? Yeah, unfortunately GoLand does not have an option for that, AFAICT. At least not in the "on commit" workflow. This is the "on commit" settings dialog so you can see the options it offers: https://shottr.cc/s/1uUn/SCR-20240901-5of I can certainly reach out to JetBrains and submit a feature request for them to address this from their end — which I will do — but as you mention `go fmt` probably should not fail on this, so fixing from both ends would be ideal. > 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. Yeah, you are probably correct on the timeframe. Thank you for engaging on this. > On Aug 31, 2024, at 12:30 PM, peterGo <go.peter...@gmail.com> wrote: > > Mike, > > I get the same results for go1.22 and go1.23 as I got for go (devel go1.24). > > I indented the src/cmd/tools/tools.go file import statement by a tab to force > a reformat. I probably did something wrong when testing with go1.22.6 then. But either way, we confirmed that the problematic behavior does in-fact occur with `go fmt`. Ian — if you are reading this — does this rise enough to the level of a bug — checking imports on a `go fmt` — that I should submit as an issue on GitHub? -Mike > > >> On Aug 30, 2024, at 9:14 AM, peterGo <go.peter...@gmail.com >> <mailto: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 >> <http://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/062E82A6-F708-4ECC-9A84-EE03DE9005A2%40newclarity.net.