From 702b70455b9e7b433ea0ae339923df4e1a4051a4 Mon Sep 17 00:00:00 2001 From: Ryan Olds Date: Sun, 29 Jan 2023 11:53:08 -0800 Subject: [PATCH] Added tests from reported issues about Generics --- testdata/sqlx_examples/correct_generics.go | 0 testdata/sqlx_examples/expected_results.txt | 2 ++ testdata/sqlx_examples/failure_generics.go | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) delete mode 100644 testdata/sqlx_examples/correct_generics.go create mode 100644 testdata/sqlx_examples/failure_generics.go diff --git a/testdata/sqlx_examples/correct_generics.go b/testdata/sqlx_examples/correct_generics.go deleted file mode 100644 index e69de29..0000000 diff --git a/testdata/sqlx_examples/expected_results.txt b/testdata/sqlx_examples/expected_results.txt index e9c7e88..cae2c9e 100644 --- a/testdata/sqlx_examples/expected_results.txt +++ b/testdata/sqlx_examples/expected_results.txt @@ -1,3 +1,5 @@ # github.com/ryanrolds/sqlclosecheck/testdata/sqlx_examples +testdata/sqlx_examples/failure_generics.go:6:21: Rows/Stmt was not closed +testdata/sqlx_examples/failure_generics.go:13:21: Rows/Stmt was not closed testdata/sqlx_examples/missing_close.go:10:24: Rows/Stmt was not closed testdata/sqlx_examples/non_defer_close.go:30:12: Close should use defer diff --git a/testdata/sqlx_examples/failure_generics.go b/testdata/sqlx_examples/failure_generics.go new file mode 100644 index 0000000..6fe970e --- /dev/null +++ b/testdata/sqlx_examples/failure_generics.go @@ -0,0 +1,17 @@ +package sqlx_examples + +import "database/sql" + +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() { + + } +}