Go version

go version go1.24.3 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/shagohead/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/shagohead/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/42/bbf9km4n01gcwwq1swy33tlw0000gn/T/go-build3288280414=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/shagohead/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/shagohead/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.3/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/shagohead/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.3/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.3'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Looks like Command.Lookup have a typo and checks command itself instead of subcommands at each subcommand iteration

What did you see happen?

On each iteration of range c.Commands condition checks name of subcommand and checks if c is runnable or has subcommands. Looks like it should check that for sub.

What did you expect to see?

diff --git a/src/cmd/go/internal/base/base.go b/src/cmd/go/internal/base/base.go
index 83cbad401e..6b203575a8 100644
--- a/src/cmd/go/internal/base/base.go
+++ b/src/cmd/go/internal/base/base.go
@@ -66,7 +66,7 @@ var Go = &Command{
 // Such subcommands are only for use as arguments to "help".
 func (c *Command) Lookup(name string) *Command {
    for _, sub := range c.Commands {
-       if sub.Name() == name && (len(c.Commands) > 0 || c.Runnable()) {
+       if sub.Name() == name && (len(sub.Commands) > 0 || sub.Runnable()) {
            return sub
        }
    }

Comment From: gabyhelp

Related Issues

Related Code Changes

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: seankhliao

Do you want to send a CL? https://go.dev/doc/contribute

Comment From: shagohead

Do you want to send a CL? https://go.dev/doc/contribute

Yes, i want. But my Google CLA is not signed

Edit: Oh, I realized that I need to «Edit» CLA by myself and then I can «Sign» it 🤦‍♂️.

Comment From: gopherbot

Change https://go.dev/cl/678655 mentions this issue: cmd/go: check subcommand properties