Skip to content

Unexpected splitting of function arguments #235

@twpayne

Description

@twpayne

Given the following code (constraints, slices, and maps are the golang.org/x/exp packages of the same name):

func SortedKeys[K interface {
	comparable
	constraints.Ordered
}, V any](m map[K]V) []K {
	keys := maps.Keys(m)
	slices.Sort(keys)
	return keys
}

gofumpt@latest (900c61a) reformats this to:

func SortedKeys[K interface {
	comparable
	constraints.Ordered
}, V any](m map[K]V,
) []K {
	keys := maps.Keys(m)
	slices.Sort(keys)
	return keys
}

which has this diff:

--- a   2022-06-19 16:24:24.237245879 +0000
+++ b   2022-06-19 16:25:48.403318940 +0000
@@ -1,7 +1,8 @@
 func SortedKeys[K interface {
        comparable
        constraints.Ordered
-}, V any](m map[K]V) []K {
+}, V any](m map[K]V,
+) []K {
        keys := maps.Keys(m)
        slices.Sort(keys)
        return keys

I did not expect the function arguments to be split over two lines. I'm only starting to learn generics, so this might however be idiomatic. Please do close this issue if it is invalid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions