golang/go

cmd/vet: should check unreachable code after os.Exit() like after panic()

Open

#74,585 创建于 2025年7月11日

在 GitHub 查看
 (7 评论) (0 反应) (0 负责人)Go (19,008 fork)batch import
NeedsInvestigationhelp wanted

仓库指标

Star
 (133,883 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Go version

go1.24.4

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/apocalypse555/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/apocalypse555/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1252593989=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/apocalypse555/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/apocalypse555/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/apocalypse555/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.4'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I run go vet on this code :

func ok(a int) bool {
	if a < 10 {
		//panic(`with that, it's well detected`)
		os.Exit(1)
		return false
	}
	return true
}

(https://go.dev/play/p/CHtVr0fs-yw)

What did you see happen?

No warning like with panic().

What did you expect to see?

A warning like with panic().

It seems odd that an unreachable code is detected after a panic() but not after an os.Exit().

Related issue

https://github.com/golang/go/issues/53968

贡献者指南