Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected splitting of function arguments #235

Closed
twpayne opened this issue Jun 19, 2022 · 4 comments
Closed

Unexpected splitting of function arguments #235

twpayne opened this issue Jun 19, 2022 · 4 comments

Comments

@twpayne
Copy link
Contributor

twpayne commented Jun 19, 2022

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.

@mvdan
Copy link
Owner

mvdan commented Jun 19, 2022

This rule was tested before the introduction of generics, so my best guess is that this is unintended :) Have you tried the latest master version as well, to see if the same problem occurs?

cc @Oiyoo

@twpayne
Copy link
Contributor Author

twpayne commented Jun 19, 2022

Yes, I've tested with the latest master (900c61a) and the same problem occurs.

@ainar-g
Copy link

ainar-g commented Jul 15, 2022

I can confirm that this is an issue on v0.3.2-0.20220627183521-8dda8068d9f3, which is the latest commit in master.

@meain
Copy link

meain commented Dec 6, 2022

Here is a possible another case:

package  fact
func

Factorial(x    int)     int {

	return x * Factorial(x   -  1,
)
    }

converted to:

package fact

func Factorial(x int,
) int {
	return x * Factorial(x-1)
}

@mvdan mvdan closed this as completed in 8b01b13 Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants