Skip to content

x/tools/gopls: incorrect varargs handling for add test action #76682

@IlyasYOY

Description

@IlyasYOY

What version of Go are you using (go version)?

$ go version
go version go1.25.5 darwin/arm64

Does this issue reproduce with the latest release?

Yes, I checked with: golang.org/x/tools/gopls v0.20.0

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
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='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/ilyasyoy/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/ilyasyoy/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/f2/s841xw414zqfscfkvn76cfv40000gn/T/go-build1666804876=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/ilyasyoy/Projects/IlyasYOY/experiments/varargs-generate-test-gopls/go.mod'
GOMODCACHE='/Users/ilyasyoy/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/ilyasyoy/go'
GOPRIVATE=''
GOPROXY='direct'
GOROOT='/opt/homebrew/Cellar/go/1.25.5/libexec'
GOSUMDB='off'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/ilyasyoy/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.25.5/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.5'
GOWORK=''
PKG_CONFIG='pkg-config'
uname -v: Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:03 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T8112
ProductName:		macOS
ProductVersion:		26.1
BuildVersion:		25B78
lldb --version: lldb-1703.0.234.3
Apple Swift version 6.2.1 (swiftlang-6.2.1.4.8 clang-1700.4.4.1)

What did you do?

  • created a file with the code:
package varargsgeneratetestgopls

import (
	"fmt"
	"strings"
)

func VarArgsFunc(args ...string) string {
	joined := strings.Join(args, ", ")
	return fmt.Sprintf("VarArgsFunc: %s", joined)
}
  • called the add test action.
Image

What did you expect to see?

func TestVarArgsFunc(t *testing.T) {
	tests := []struct {
		name string // description of this test case
		// Named input parameters for target function.
		args []string
		want string
	}{
		// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := varargsgeneratetestgopls.VarArgsFunc(tt.args...) 
			// TODO: update the condition below to compare got with tt.want.
			if true {
				t.Errorf("VarArgsFunc() = %v, want %v", got, tt.want)
			}
		})
	}
}

What did you see instead?

I've got the test with syntax error:

package varargsgeneratetestgopls_test

import (
	"testing"

	"github.com/IlyasYOY/varargs-generate-test-gopls"
)

func TestVarArgsFunc(t *testing.T) {
	tests := []struct {
		name string // description of this test case
		// Named input parameters for target function.
		args []string
		want string
	}{
		// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := varargsgeneratetestgopls.VarArgsFunc(tt.args) // <- error here, must be: tt.args... 
			// TODO: update the condition below to compare got with tt.want.
			if true {
				t.Errorf("VarArgsFunc() = %v, want %v", got, tt.want)
			}
		})
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions