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

Linter proposal: warn if returning a typed nil #3973

Open
mitar opened this issue Jul 24, 2023 · 2 comments
Open

Linter proposal: warn if returning a typed nil #3973

mitar opened this issue Jul 24, 2023 · 2 comments
Labels
linter: idea idea of a linter

Comments

@mitar
Copy link
Contributor

mitar commented Jul 24, 2023

Your feature request related to a problem? Please describe.

The problem is well described in Go FAQ. It is often surprising that comparing a typed interface nil to nil is not true.

Describe the solution you'd like.

I would like to propose to make a linter which warns if a function is returning a typed nil.

Describe alternatives you've considered.

There were many potential solutions proposed for Go 2 to address that, but it looks like it is hard to find a backward compatible solution here. But on the other hand, having a typed nil on purpose is a very rare case and something which might be a reasonable false positive for a linter.

Additional context.

No response

@mitar mitar added the enhancement New feature or improvement label Jul 24, 2023
@ldez ldez added linter: idea idea of a linter and removed enhancement New feature or improvement labels Jul 24, 2023
@ldez
Copy link
Member

ldez commented Jul 25, 2023

golang/go#61372

@mitar
Copy link
Contributor Author

mitar commented Jul 25, 2023

@ldez That proposal (at its past and current iteration) does not address the issue this issue is about, because zero can be used only where nil cannot be used. And this issue is about (typed) nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linter: idea idea of a linter
Projects
None yet
Development

No branches or pull requests

2 participants