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

SSA and generics (go1.18) #18

Closed
Tracked by #2649
ldez opened this issue Mar 24, 2022 · 7 comments
Closed
Tracked by #2649

SSA and generics (go1.18) #18

ldez opened this issue Mar 24, 2022 · 7 comments

Comments

@ldez
Copy link

ldez commented Mar 24, 2022

Currently, SSA is not working with generics.

So your linter produces a panic when it is used with generics.

There is an issue open about that in the Go repository: golang/go#48525

Inside golangci-lint, we have disabled your linters: golangci/golangci-lint#2649

You have 2 solutions:

  • waiting for a version of SSA that will support generics
  • dropping the SSA analyzers and using something else to analyze the code.

Related to golang/go#50558

@ldez
Copy link
Author

ldez commented Jul 19, 2022

SSA has been updated and it seems to work inside golangci-lint.

@ldez ldez closed this as completed Jul 19, 2022
@ldez
Copy link
Author

ldez commented Jul 19, 2022

in fact, the problem is still here

@ldez ldez reopened this Jul 19, 2022
@ldez
Copy link
Author

ldez commented Jul 19, 2022

The code of the linter needs to be adapted to manage generics:

func SqlCloseCheck(db *sql.DB, a int) {
	rows, _ := db.Query("select id from tb") // <- detected OK
	for rows.Next() {

	}
}

func SqlCloseCheckG[T ~int64](db *sql.DB, a T) {
	rows, _ := db.Query("select id from tb") // <- not detected KO
	for rows.Next() {

	}
}

@ldez
Copy link
Author

ldez commented Jul 21, 2022

go1.19 will come in about 2 weeks, it can be good if you can fix your linter before this release.

@dolmen
Copy link

dolmen commented Oct 12, 2022

@ldez For what I see above, it seems that sqlclosecheck works on code that doesn't use generics. Am I right?

So would it be possible to enable sqlclosecheck in golangci-lint to have that feature back, at least to check non-generic code?

@ldez
Copy link
Author

ldez commented Oct 12, 2022

you can add the following option to your configuration:

run:
  # ...
  go: go1.17

@ryanrolds
Copy link
Owner

I believe I've resolved the panic and it's detecting the provided Generics test case. A pre-release has been cut and I will be testing on some personal projects to build confidence.

Thank you for your patience. I will close after building some confidence.

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

3 participants