Skip to content

unnecessary type arguments infertypeargs #5488

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

Closed
2 of 3 tasks
jiaopengzi opened this issue Mar 2, 2025 · 3 comments
Closed
2 of 3 tasks

unnecessary type arguments infertypeargs #5488

jiaopengzi opened this issue Mar 2, 2025 · 3 comments
Labels
question Further information is requested

Comments

@jiaopengzi
Copy link

jiaopengzi commented Mar 2, 2025

Welcome

How did you install golangci-lint?

go install

Your feature request related to a problem? Please describe

Hello,

After upgrading to Go version 1.24.0, we noticed that the generic type parameters no longer need to be explicitly specified as they can be inferred automatically.

Previously, the code would be written as follows:

func f[T any](T) {}
	
func _() {
	f[string]("foo")
}

Now, it can be written as:

func f[T any](T) {}
	
func _() {
	f("foo") // string could be inferred
}

Official reference: link

If the old style is still used, the editor already provides a hint: unnecessary type arguments infertypeargs.

However, running golangci-lint run currently does not detect this issue. We would appreciate it if this functionality could be added.

golangci-lint:v1.64.5

Thank you very much.

Describe the solution you'd like

We hope that golangci-lint run will provide a warning for the issue unnecessary type arguments infertypeargs.

Describe alternatives you've considered

I apologize for my lack of expertise in this area. I can only raise the issue and currently do not have the capability to solve it.

Additional context

No response

Supporter

@jiaopengzi jiaopengzi added the enhancement New feature or improvement label Mar 2, 2025
Copy link

boring-cyborg bot commented Mar 2, 2025

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez ldez removed the enhancement New feature or improvement label Mar 2, 2025
@golangci golangci locked and limited conversation to collaborators Mar 2, 2025
@ldez ldez converted this issue into a discussion Mar 2, 2025
@ldez ldez reopened this Mar 2, 2025
@ldez ldez converted this issue into a discussion Mar 2, 2025
@ldez ldez reopened this Mar 2, 2025
@ldez ldez pinned this issue Mar 2, 2025
@ldez ldez unpinned this issue Mar 2, 2025
@golangci golangci unlocked this conversation Mar 2, 2025
@golangci golangci locked and limited conversation to collaborators Mar 2, 2025
@golangci golangci unlocked this conversation Mar 2, 2025
@golangci golangci locked and limited conversation to collaborators Mar 2, 2025
@ldez ldez converted this issue into a discussion Mar 2, 2025
@ldez ldez reopened this Mar 2, 2025
@golangci golangci unlocked this conversation Mar 2, 2025
@ldez
Copy link
Member

ldez commented Mar 2, 2025

After upgrading to Go version 1.24.0, we noticed that the generic type parameters no longer need to be explicitly specified as they can be inferred automatically.

The type inference exists since the introduction of generics (go1.18), it is not related to go1.24 or a new element.

But I will try to see if I can implement an analyzer of the topic.


Note: there is a GitHub bug with converting an issue to discussion: https://github.com/orgs/community/discussions/152627

@ldez ldez added the question Further information is requested label Mar 2, 2025
@ldez
Copy link
Member

ldez commented Mar 2, 2025

Ok, you are referring to a gopls analyzer.

#686 (comment)

@ldez ldez closed this as completed Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants