Go version

go version go1.24.5 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='<user>'
GOBIN=''
GOCACHE='/Users/<user>/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/<user>/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/ry/2b9y04m53nj1qyqwx_nz3r9w0000gp/T/go-build3428016216=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/<user>/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/<user>/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/<user>/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.5'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Proposal: Optional Compile-Time Error for Unused Function Parameters

Background

Go currently allows unused function parameters without compilation errors, which is intentional for interface compatibility. However, this design choice can lead to subtle bugs where parameters are silently ignored, causing unexpected behavior.

Real-World Example

We encountered this issue in our codebase:

```go func SumThreeNumbers(a int, b int, c int) int { return 3 }

What did you see happen?

Function signature promises to use a, b, c but ignores them Silent failure mode - no compilation or obvious runtime error Required workarounds in calling code: unused variables

What did you expect to see?

I wanted to see compile time error when the variables in the signature of the function isn't used in function definition. This would make Go a robust language without creating a havoc in the developer environment

Comment From: gabyhelp

Related Issues

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

Comment From: seankhliao

gopls' unusedparams analyzer is the more suited place for this https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/unusedparams

Comment From: kiranbharadwajhd

Hi Go Team,

I would like to request the reopening of this issue for the following reasons:

Importance of Detecting Unused Parameters

  1. Improved Code Quality: Detecting unused parameters at compile time can significantly improve code quality by preventing the accumulation of unused and potentially confusing code.

  2. Error Prevention: Unused parameters can lead to subtle bugs where developers might think parameters are being used when they are not. This can cause unexpected behavior and make debugging more difficult.

  3. Consistency with Other Languages: Many other programming languages provide warnings or errors for unused parameters, which helps maintain cleaner codebases.

Real-World Impact

This is an example. We encountered an issue in our codebase where unused parameters led to confusion and potential bugs:

```go func SumThreeNumbers(a int, b int, c int) int { return 3 }

Comment From: randall77

We don't normally add compiler flags that do diagnostics like this. We leave that to linting tools. See https://go.dev/wiki/CodeTools. I would think staticcheck would be the right place for such a detector.