Skip to content

x/tools/gopls: "Create function" generates a parameter list that does not parse #81810

Closed

Description

@wangzhihao-lab

gopls version

golang.org/x/tools/gopls v0.23.0 (h1:Dn6mf9WXu9iLnTftDDMb9wV0c6Se7PjzEMqP0LEe08Y=), built with go1.27.1.
v0.23.0 is still the newest gopls release (checked 2026-09-28); reproduces on it again in 3 of 3 runs.
Same result with gopls v0.20.0.

go env

GOARCH=arm64
GOOS=darwin
GOVERSION=go1.27.1
GOFLAGS=-modcacherw
GOTOOLCHAIN=local

(macOS 27 on Apple silicon; path variables left out.)

What did you do?

I drive gopls over LSP from a small script. junegunn/fzf at b1be3a8be1b833ce5b92fbbac11637643d60a046, src/pattern_test.go. I misspelled buildPattern as buildPttern on line 163 (1-based):

func TestCacheKey(t *testing.T) {
	test := func(extended bool, patStr string, expected string, cacheable bool) {
		pat := buildPttern(true, algo.FuzzyMatchV2, extended, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune(patStr))

gopls reports undefined: buildPttern (UndeclaredName) and offers "Create function buildPttern". I applied it. It inserts this after TestCacheKey (new line 183):

func buildPttern(true1 bool, result, *[]int func(caseSensitive bool, normalize bool, forward bool, input *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (algo.Result, *[]int), extended bool, CaseSmart Case, false1, true2, false2, true3 bool, range []Range, delimiter Delimiter, r []rune) any {
	panic("unimplemented")
}

What did you see happen?

The file no longer parses (before the typo go vet ./src and gofmt -e pass; after the typo only the undefined error is reported):

$ gofmt -e src/pattern_test.go
src/pattern_test.go:183:38: missing parameter name
src/pattern_test.go:183:45: missing ',' in parameter list
src/pattern_test.go:183:64: expected ')', found bool
src/pattern_test.go:183:187: expected ';', found ','
src/pattern_test.go:183:189: expected declaration, found extended
src/pattern_test.go:257:2: expected declaration, found runtime
src/pattern_test.go:264:2: expected declaration, found runtime
src/pattern_test.go:283:3: expected declaration, found 'for'
$ go vet ./src
src/pattern_test.go:183:45: missing ',' in parameter list

gopls itself reports missing parameter name at 183:38 right after the edit. Two parts of the generated signature are not valid Go:

  • the parameter for the argument algo.FuzzyMatchV2 (a function) is written as result, *[]int func(...) (algo.Result, *[]int);
  • the parameter for []Range{} is named range, which is a keyword.

Same in 3 of 3 runs.

What did you expect to see?

A declaration that parses, for example a name like fn for the function-typed parameter and a non-keyword name such as ranges for the []Range one.

The any result type is a separate matter (see #77272, closed as a duplicate); this report is only about the parameter list.

Editor and settings

No editor; a script over stdio (gopls serve). Settings returned for workspace/configuration: {"semanticTokens": true, "hints": {"assignVariableTypes": true, "compositeLiteralFields": true, "compositeLiteralTypes": true, "constantValues": true, "functionTypeParameters": true, "parameterNames": true, "rangeVariableTypes": true}}.

Logs

LSP trace

F stands for the URI of src/pattern_test.go; positions are 0-based.

--> textDocument/didChange {"textDocument":{"uri":F,"version":2},"contentChanges":[{"range":{"start":{"line":162,"character":9},"end":{"line":162,"character":21}},"text":"buildPttern"}]}
<-- textDocument/publishDiagnostics {"uri":F,"version":2,"diagnostics":[{"range":{"start":{"line":162,"character":9},"end":{"line":162,"character":20}},"severity":1,"code":"UndeclaredName","source":"compiler","message":"undefined: buildPttern"}]}
--> textDocument/codeAction {"textDocument":{"uri":F},"range":{"start":{"line":162,"character":9},"end":{"line":162,"character":20}},"context":{"diagnostics":[(the diagnostic above)],"only":["quickfix"],"triggerKind":1}}
<-- [{"title":"Create function buildPttern","kind":"quickfix","data":{"title":"Create function buildPttern","command":"gopls.apply_fix",
      "arguments":[{"Fix":"create_undeclared","Location":{"uri":F,"range":{"start":{"line":162,"character":9},"end":{"line":162,"character":20}}},"ResolveEdits":true}]}}]
--> codeAction/resolve (that action)
<-- {"title":"Create function buildPttern","kind":"quickfix","edit":{"documentChanges":[{"textDocument":{"version":2,"uri":F},"edits":[
      {"range":{"start":{"line":180,"character":1},"end":{"line":180,"character":1}},
       "newText":"\n\nfunc buildPttern(true1 bool, result, *[]int func(caseSensitive bool, normalize bool, forward bool, input *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (algo.Result, *[]int), extended bool, CaseSmart Case, false1, true2, false2, true3 bool, range []Range, delimiter Delimiter, r []rune) any {\n\tpanic(\"unimplemented\")\n}"}]}]}}
--> textDocument/didChange (the edit above, version 3)
<-- textDocument/publishDiagnostics {"uri":F,"version":3,"diagnostics":[{"range":{"start":{"line":182,"character":37},"end":{"line":182,"character":37}},"severity":1,"source":"syntax","message":"missing parameter name"}]}

Activity

  1. added
    ToolsThis label describes issues relating to any tools in the x/tools repository.
    goplsIssues related to the Go language server, gopls.
    on Sep 28, 2026
  2. added this to the Unreleased milestone on Sep 28, 2026
  3. gabyhelp commented on Sep 28, 2026

    @gabyhelp
  4. gopherbot commented on Oct 1, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/843125 mentions this issue: gopls/internal/test/marker: add test for invalid "Create function" params

  5. h9jiang commented on Oct 1, 2026

    @h9jiang
    Member

    I just created a CL for including the failing cases and I think this issue can be fixed by open source contributor as it is not that complicated.

    +Help Wanted.

  6. Tiancheng-Xu commented on Oct 2, 2026

    @Tiancheng-Xu

    I’d like to work on this issue. I’ll fix generation of function-typed and keyword-named parameters, add focused gopls regression coverage, and run the relevant tests.

  7. added a commit that references this issue on Oct 2, 2026
    e9f8ae5
  8. gopherbot commented on Oct 2, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/843605 mentions this issue: gopls/internal/golang: generate valid names for new function parameters

  9. h9jiang commented on Oct 2, 2026

    @h9jiang
    Member

    Look like some one already has a CL for that... @Tiancheng-Xu do you want to take #81808?

    You will need to make a comment in that issue so I can assign it to you.

  10. gopherbot commented on Oct 5, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/845405 mentions this issue: gopls/internal/golang: replace assignment with declaration

  11. gopherbot commented on Oct 11, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/848505 mentions this issue: gopls/internal/golang: emit parseable Create function parameter lists

  12. added 2 commits that reference this issue on Oct 15, 2026
    da285f8
    85ca19d
  13. gopherbot commented on Oct 15, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/849685 mentions this issue: gopls/internal/test/marker: simplify undeclared test function name

  14. added a commit that references this issue on Oct 16, 2026
    95c53bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.help wanted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions