Skip to content

cmd/gofmt: gofmt -r doesn't handle variadic values very well #5059

@fsouza

Description

@fsouza
When formatting function calls that provide variadic arguments using `slice...`, gofmt
drops "...":

% cat sample.go
package main

func doSomething(args ...string) {
}

func main() {
    values := []string{"a", "b"}
    doSomething(values...)
}
% gofmt -r 'doSomething(a) -> DoSomething(a)' sample.go
package main

func doSomething(args ...string) {
}

func main() {
    values := []string{"a", "b"}
    DoSomething(values)
}

It rewrote doSomething(values...) to DoSomething(values), meaning that the code does not
compile anymore.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions