Skip to content

Commit

Permalink
Cleanup compile warnings in 2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
jatcwang committed Jan 6, 2024
1 parent a137e78 commit 8337e1b
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 22 deletions.
11 changes: 10 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ lazy val free = project
classOf[java.sql.ResultSet]
)
},
freeGen2KleisliInterpreterImportExcludes := Set[Class[_]](
freeGen2AllImportExcludes := Set[Class[_]](
classOf[java.util.Map[_, _]],
),
freeGen2KleisliInterpreterImportExcludes := Set[Class[_]](
classOf[java.sql.DriverPropertyInfo],
classOf[java.io.Writer],
classOf[java.io.OutputStream]
Expand Down Expand Up @@ -313,6 +315,13 @@ lazy val postgres = project
classOf[org.postgresql.copy.CopyIn] -> "PGCopyIn",
classOf[org.postgresql.copy.CopyManager] -> "PGCopyManager",
classOf[org.postgresql.copy.CopyOut] -> "PGCopyOut",
),
freeGen2AllImportExcludes := Set[Class[_]](
classOf[java.util.Map[_, _]],
),
freeGen2KleisliInterpreterImportExcludes := Set[Class[_]](
classOf[java.sql.Array],
classOf[org.postgresql.copy.CopyDual]
),
initialCommands := """
import cats._, cats.data._, cats.implicits._, cats.effect._
Expand Down
19 changes: 10 additions & 9 deletions modules/core/src/test/scala/doobie/util/GetSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import doobie.enumerated.JdbcType

import scala.annotation.nowarn

@nowarn("msg=.*pure expression does nothing in statement position.*")
class GetSuite extends munit.FunSuite with GetSuitePlatform {

case class X(x: Int)
Expand All @@ -19,32 +20,32 @@ class GetSuite extends munit.FunSuite with GetSuitePlatform {
object S

test("Get should exist for primitive types") {
Get[Int]
Get[String]
val _ = Get[Int]
val _ = Get[String]
}

test("Get should be auto derived for unary products") {
import doobie.generic.auto._

Get[X]
Get[Q]
val _ = Get[X]
val _ = Get[Q]
}

test("Get is not auto derived without an import") {
compileErrors("Get[X]")
compileErrors("Get[Q]")
val _ = compileErrors("Get[X]")
val _ = compileErrors("Get[Q]")
}

test("Get can be manually derived for unary products") {
Get.derived[X]
Get.derived[Q]
val _ = Get.derived[X]
val _ = Get.derived[Q]
}

test("Get should not be derived for non-unary products") {
compileErrors("Get[Z]")
compileErrors("Get[(Int, Int)]")
compileErrors("Get[S.type]")
}: @nowarn("msg=.*pure expression does nothing in statement position.*")
}

}

Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/test/scala/doobie/util/PutSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import doobie._

import scala.annotation.nowarn

@nowarn("msg=.*pure expression does nothing in statement position.*")
class PutSuite extends munit.FunSuite with PutSuitePlatform {
case class X(x: Int)
case class Q(x: String)
Expand Down Expand Up @@ -58,6 +59,6 @@ class PutSuite extends munit.FunSuite with PutSuitePlatform {
compileErrors("Put[Z]")
compileErrors("Put[(Int, Int)]")
compileErrors("Put[S.type]")
}: @nowarn("msg=.*pure expression does nothing in statement position.*")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import java.sql.Time
import java.sql.Timestamp
import java.sql.{ Array => SqlArray }
import java.util.Calendar
import java.util.Map

// This file is Auto-generated using FreeGen2.scala
object callablestatement { module =>
Expand Down
1 change: 0 additions & 1 deletion modules/free/src/main/scala/doobie/free/connection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import java.sql.ShardingKey
import java.sql.Statement
import java.sql.Struct
import java.sql.{ Array => SqlArray }
import java.util.Map
import java.util.Properties
import java.util.concurrent.Executor

Expand Down
1 change: 0 additions & 1 deletion modules/free/src/main/scala/doobie/free/ref.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import scala.concurrent.duration.FiniteDuration

import java.lang.String
import java.sql.Ref
import java.util.Map

// This file is Auto-generated using FreeGen2.scala
object ref { module =>
Expand Down
1 change: 0 additions & 1 deletion modules/free/src/main/scala/doobie/free/resultset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import java.sql.Time
import java.sql.Timestamp
import java.sql.{ Array => SqlArray }
import java.util.Calendar
import java.util.Map

// This file is Auto-generated using FreeGen2.scala
object resultset { module =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ import java.io.Reader
import java.io.Writer
import java.lang.Class
import java.lang.String
import java.sql.{ Array => SqlArray }
import java.util.Map
import org.postgresql.PGConnection
import org.postgresql.PGNotification
import org.postgresql.copy.{ CopyDual => PGCopyDual }
import org.postgresql.copy.{ CopyIn => PGCopyIn }
import org.postgresql.copy.{ CopyManager => PGCopyManager }
import org.postgresql.copy.{ CopyOut => PGCopyOut }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import scala.concurrent.duration.FiniteDuration
import java.lang.Class
import java.lang.String
import java.sql.{ Array => SqlArray }
import java.util.Map
import org.postgresql.PGConnection
import org.postgresql.PGNotification
import org.postgresql.copy.{ CopyManager => PGCopyManager }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import cats.syntax.all._
import doobie._
import doobie.implicits._
import doobie.postgres._
import doobie.postgres.implicits._
import fs2._

import java.io.StringReader
Expand Down
8 changes: 6 additions & 2 deletions project/FreeGen2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object FreeGen2 {
lazy val freeGen2Dir = settingKey[File]("directory where free algebras go")
lazy val freeGen2Package = settingKey[String]("package where free algebras go")
lazy val freeGen2Renames = settingKey[Map[Class[_], String]]("map of imports that must be renamed")
lazy val freeGen2AllImportExcludes = settingKey[Set[Class[_]]]("Imports to exclude for the generator for all generaated files")
lazy val freeGen2KleisliInterpreterImportExcludes = settingKey[Set[Class[_]]]("Imports to exclude for the generator kleisliinterpreter.scala file (to avoid unused import warning) ")
lazy val freeGen2 = taskKey[Seq[File]]("generate free algebras")

Expand All @@ -22,11 +23,13 @@ object FreeGen2 {
freeGen2Package := "doobie.free",
freeGen2Renames := Map(classOf[java.sql.Array] -> "SqlArray"),
freeGen2KleisliInterpreterImportExcludes := Set.empty,
freeGen2AllImportExcludes := Set.empty,
freeGen2 :=
new FreeGen2(
freeGen2Classes.value,
freeGen2Package.value,
freeGen2Renames.value,
freeGen2AllImportExcludes.value,
freeGen2KleisliInterpreterImportExcludes.value,
state.value.log
).gen(freeGen2Dir.value),
Expand All @@ -38,6 +41,7 @@ class FreeGen2(
managed: List[Class[_]],
pkg: String,
renames: Map[Class[_], String],
allImportExcludes: Set[Class[_]],
kleisliImportExcludes: Set[Class[_]],
log: Logger
) {
Expand Down Expand Up @@ -240,7 +244,7 @@ class FreeGen2(
|import scala.concurrent.Future
|import scala.concurrent.duration.FiniteDuration
|
|${imports[A](excludeImports = Set.empty).mkString("\n")}
|${imports[A](excludeImports = allImportExcludes).mkString("\n")}
|
|// This file is Auto-generated using FreeGen2.scala
|object $mname { module =>
Expand Down Expand Up @@ -505,7 +509,7 @@ class FreeGen2(
|import scala.concurrent.duration.FiniteDuration
|
|// Types referenced in the JDBC API
|${managed.map(ClassTag(_)).flatMap(c => imports(kleisliImportExcludes)(c)).distinct.sorted.mkString("\n")}
|${managed.map(ClassTag(_)).flatMap(c => imports(kleisliImportExcludes ++ allImportExcludes)(c)).distinct.sorted.mkString("\n")}
|
|// Algebras and free monads thereof referenced by our interpreter.
|${managed.map(_.getSimpleName).map(c => s"import ${pkg}.${c.toLowerCase}.{ ${c}IO, ${c}Op }").mkString("\n")}
Expand Down

0 comments on commit 8337e1b

Please sign in to comment.