From f14654d24b893a5033ffb724bb3c86373d819ef3 Mon Sep 17 00:00:00 2001 From: Hugh Simpson Date: Tue, 28 Nov 2023 13:58:55 +0000 Subject: [PATCH] fix more scala 3 compile errors --- README.md | 4 ++-- .../tminglei/slickpg/PgDateSupportJoda.scala | 3 --- .../slickpg/PgDateSupportJodaSuite.scala | 2 +- .../slickpg/PgPlayJsonSupportSuite.scala | 8 ++++++- .../slickpg/geom/PgPostGISExtensions.scala | 12 +++++----- .../slickpg/str/PgStringExtensions.scala | 4 ++-- .../main/scala/demo/MyPostgresDriver.scala | 2 +- .../app/util/MyPostgresDriver.scala | 2 +- .../tminglei/slickpg/PgDate2Support.scala | 1 - .../tminglei/slickpg/PgDateSupport.scala | 3 --- .../tminglei/slickpg/MyPostgresProfile.scala | 2 +- .../slickpg/PgArraySupportSuite.scala | 4 ++-- .../slickpg/PgCompositeSupportSuite.scala | 2 +- .../tminglei/slickpg/PgEnumSupportSuite.scala | 22 +++++++++---------- 14 files changed, 35 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 10c25464..eab4dc45 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ trait MyPostgresProfile extends ExPostgresProfile override val api = MyAPI object MyAPI extends ExtPostgresAPI with ArrayImplicits - with DateTimeImplicits + with Date2DateTimeImplicitsDuration with JsonImplicits with NetImplicits with LTreeImplicits @@ -91,7 +91,7 @@ class TestTable(tag: Tag) extends Table[Test](tag, Some("xxx"), "Test") { def props = column[Map[String,String]]("props_hstore") def tags = column[List[String]]("tags_arr") - def * = (id, during, location, text, props, tags) <> (Test.tupled, Test.unapply) + def * = (id, during, location, text, props, tags) <> ((Test.apply _).tupled, Test.unapply) } object tests extends TableQuery(new TestTable(_)) { diff --git a/addons/joda-time/src/main/scala/com/github/tminglei/slickpg/PgDateSupportJoda.scala b/addons/joda-time/src/main/scala/com/github/tminglei/slickpg/PgDateSupportJoda.scala index d15c8277..d4dc0dbe 100644 --- a/addons/joda-time/src/main/scala/com/github/tminglei/slickpg/PgDateSupportJoda.scala +++ b/addons/joda-time/src/main/scala/com/github/tminglei/slickpg/PgDateSupportJoda.scala @@ -22,9 +22,6 @@ trait PgDateSupportJoda extends date.PgDateExtensions with utils.PgCommonJdbcTyp } } - /// alias - trait DateTimeImplicits extends JodaDateTimeImplicits - trait JodaDateTimeFormatters { val jodaDateFormatter = ISODateTimeFormat.date() val jodaTimeFormatter = DateTimeFormat.forPattern("HH:mm:ss.SSSSSS") diff --git a/addons/joda-time/src/test/scala/com/github/tminglei/slickpg/PgDateSupportJodaSuite.scala b/addons/joda-time/src/test/scala/com/github/tminglei/slickpg/PgDateSupportJodaSuite.scala index 7c27f9ec..ed2c6ccc 100644 --- a/addons/joda-time/src/test/scala/com/github/tminglei/slickpg/PgDateSupportJodaSuite.scala +++ b/addons/joda-time/src/test/scala/com/github/tminglei/slickpg/PgDateSupportJodaSuite.scala @@ -18,7 +18,7 @@ class PgDateSupportJodaSuite extends AnyFunSuite with PostgresContainer { val plainAPI = new API with JodaDateTimePlainImplicits /// - trait API extends JdbcAPI with DateTimeImplicits + trait API extends JdbcAPI with JodaDateTimeImplicits } object MyPostgresProfile extends MyPostgresProfile diff --git a/addons/play-json/src/test/scala/com/github/tminglei/slickpg/PgPlayJsonSupportSuite.scala b/addons/play-json/src/test/scala/com/github/tminglei/slickpg/PgPlayJsonSupportSuite.scala index f9c81fa7..64384ccb 100644 --- a/addons/play-json/src/test/scala/com/github/tminglei/slickpg/PgPlayJsonSupportSuite.scala +++ b/addons/play-json/src/test/scala/com/github/tminglei/slickpg/PgPlayJsonSupportSuite.scala @@ -7,6 +7,7 @@ import play.api.libs.json._ import slick.jdbc.{GetResult, JdbcType, PostgresProfile} import com.github.tminglei.slickpg.utils.JsonUtils import org.scalatest.funsuite.AnyFunSuite +import play.api.libs.functional.syntax.toFunctionalBuilderOps import slick.ast.BaseTypedType @@ -15,7 +16,12 @@ class PgPlayJsonSupportSuite extends AnyFunSuite with PostgresContainer { case class JBean(name: String, count: Int) object JBean { - implicit val jbeanFmt: OFormat[JBean] = Json.format[JBean] + // jbeanFmt should just be this, but there's a bug in play-json for scala 3 that causes it to throw a java.lang.ClassCastException -- and we're not testing that here +// implicit val jbeanFmt: OFormat[JBean] = Json.format[JBean] + implicit val jbeanFmt: OFormat[JBean] = ( + (__ \ implicitly[JsonConfiguration].naming("name")).format[String] and + (__ \ implicitly[JsonConfiguration].naming("count")).format[Int] + )(JBean.apply _, x => (x.name, x.count)) implicit val jbeanWrt: OWrites[JBean] = Json.writes[JBean] } diff --git a/core/src/main/scala/com/github/tminglei/slickpg/geom/PgPostGISExtensions.scala b/core/src/main/scala/com/github/tminglei/slickpg/geom/PgPostGISExtensions.scala index 2c04914a..f3d95e4e 100644 --- a/core/src/main/scala/com/github/tminglei/slickpg/geom/PgPostGISExtensions.scala +++ b/core/src/main/scala/com/github/tminglei/slickpg/geom/PgPostGISExtensions.scala @@ -53,12 +53,12 @@ trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile = case Some(p) => om.column(GeomLibrary.LineFromEncodedPolyline, encodedPolyline.toNode, LiteralNode(p)) case None => om.column(GeomLibrary.LineFromEncodedPolyline, encodedPolyline.toNode) } - def makeBox[G1 <: GEOMETRY, P1, G2 <: GEOMETRY, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])( - implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G1, P1]#arg[G2, P2]#to[GEOMETRY, R]) = { + def makeBox[G <: GEOMETRY, P1, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])( + implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G, P1]#arg[G, P1]#to[GEOMETRY, R]) = { om.column(GeomLibrary.MakeBox, lowLeftPoint.toNode, upRightPoint.toNode) } - def makeBox3d[G1 <: GEOMETRY, P1, G2 <: GEOMETRY, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])( - implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G1, P1]#arg[G2, P2]#to[GEOMETRY, R]) = { + def makeBox3d[G <: GEOMETRY, P1, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])( + implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G, P1]#arg[G, P2]#to[GEOMETRY, R]) = { om.column(GeomLibrary.MakeBox3D, lowLeftPoint.toNode, upRightPoint.toNode) } def makeEnvelope(xmin: Rep[Double], ymin: Rep[Double], xmax: Rep[Double], ymax: Rep[Double], srid: Option[Int] = None)( @@ -75,8 +75,8 @@ trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile = case (None, Some(m)) => om.column(GeomLibrary.MakePointM, x.toNode, y.toNode, LiteralNode(m)) case (None, None) => om.column(GeomLibrary.MakePoint, x.toNode, y.toNode) } - def makeLine[G1 <: GEOMETRY, P1, G2 <: GEOMETRY, P2, R](point1: Rep[P1], point2: Rep[P2])( - implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G1, P1]#arg[G2, P2]#to[GEOMETRY, R]) = { + def makeLine[G <: GEOMETRY, P1, P2, R](point1: Rep[P1], point2: Rep[P2])( + implicit tm: JdbcType[GEOMETRY], om: OptionMapperDSL.arg[G, P1]#arg[G, P2]#to[GEOMETRY, R]) = { om.column(GeomLibrary.MakeLine, point1.toNode, point2.toNode) } def makePolygon[G <: GEOMETRY, P, R](linestring: Rep[P])( diff --git a/core/src/main/scala/com/github/tminglei/slickpg/str/PgStringExtensions.scala b/core/src/main/scala/com/github/tminglei/slickpg/str/PgStringExtensions.scala index a3e28cd5..77f1db0c 100644 --- a/core/src/main/scala/com/github/tminglei/slickpg/str/PgStringExtensions.scala +++ b/core/src/main/scala/com/github/tminglei/slickpg/str/PgStringExtensions.scala @@ -27,7 +27,7 @@ trait PgStringExtensions extends JdbcTypesComponent { driver: PostgresProfile => } class PgStringColumnExtensionMethods[P1](val c: Rep[P1]) extends ExtensionMethods[String, P1] { - protected implicit def b1Type = implicitly[TypedType[String]] + protected def b1Type = implicitly[TypedType[String]] def ilike[P2, R](e: Rep[P2])(implicit om: o#arg[String, P2]#to[Boolean, R]) = { om.column(StringLibrary.ILike, n, e.toNode) @@ -58,7 +58,7 @@ trait PgStringExtensions extends JdbcTypesComponent { driver: PostgresProfile => } class PgStringByteaColumnExtensionMethods[P1](val c: Rep[P1]) extends ExtensionMethods[Array[Byte], P1] { - protected implicit def b1Type = implicitly[TypedType[Array[Byte]]] + protected def b1Type = implicitly[TypedType[Array[Byte]]] def convert[R](srcEncoding: Rep[String], destEncoding: Rep[String])(implicit om: o#to[Array[Byte], R]) = { om.column(StringLibrary.Convert, n, srcEncoding.toNode, destEncoding.toNode) diff --git a/examples/codegen-customization/codegen/src/main/scala/demo/MyPostgresDriver.scala b/examples/codegen-customization/codegen/src/main/scala/demo/MyPostgresDriver.scala index 4d4e2c64..82493b33 100644 --- a/examples/codegen-customization/codegen/src/main/scala/demo/MyPostgresDriver.scala +++ b/examples/codegen-customization/codegen/src/main/scala/demo/MyPostgresDriver.scala @@ -16,7 +16,7 @@ trait MyPostgresDriver extends ExPostgresProfile ////// trait MyAPI extends ExtPostgresAPI with ArrayImplicits - with DateTimeImplicits + with Date2DateTimeImplicitsDuration with RangeImplicits with HStoreImplicits with SearchImplicits diff --git a/examples/play-slick-example/app/util/MyPostgresDriver.scala b/examples/play-slick-example/app/util/MyPostgresDriver.scala index c0dc8bb3..f9893229 100644 --- a/examples/play-slick-example/app/util/MyPostgresDriver.scala +++ b/examples/play-slick-example/app/util/MyPostgresDriver.scala @@ -15,7 +15,7 @@ trait MyPostgresDriver extends ExPostgresDriver override val pgjson = "jsonb" /// override val api = new ExtPostgresAPI with ArrayImplicits - with DateTimeImplicits + with Date2DateTimeImplicitsDuration with PlayJsonImplicits with NetImplicits with LTreeImplicits diff --git a/src/main/scala/com/github/tminglei/slickpg/PgDate2Support.scala b/src/main/scala/com/github/tminglei/slickpg/PgDate2Support.scala index 271a7965..a480fa8a 100644 --- a/src/main/scala/com/github/tminglei/slickpg/PgDate2Support.scala +++ b/src/main/scala/com/github/tminglei/slickpg/PgDate2Support.scala @@ -29,7 +29,6 @@ trait PgDate2Support extends date.PgDateExtensions with utils.PgCommonJdbcTypes } /// alias - trait DateTimeImplicits extends Date2DateTimeImplicitsDuration trait DateTimeImplicitsPeriod extends Date2DateTimeImplicitsPeriod trait Date2DateTimeImplicitsDuration extends Date2DateTimeImplicits[Duration] diff --git a/src/main/scala/com/github/tminglei/slickpg/PgDateSupport.scala b/src/main/scala/com/github/tminglei/slickpg/PgDateSupport.scala index e8d57e9e..2900a60d 100644 --- a/src/main/scala/com/github/tminglei/slickpg/PgDateSupport.scala +++ b/src/main/scala/com/github/tminglei/slickpg/PgDateSupport.scala @@ -8,9 +8,6 @@ import slick.jdbc.{JdbcType, PostgresProfile} trait PgDateSupport extends date.PgDateExtensions with utils.PgCommonJdbcTypes with date.PgDateJdbcTypes { driver: PostgresProfile => import driver.api._ - /// alias - trait DateTimeImplicits extends SimpleDateTimeImplicits - trait SimpleDateTimeImplicits { implicit val simpleIntervalTypeMapper: JdbcType[Interval] = new GenericJdbcType[Interval]("interval", Interval.apply, hasLiteralForm=false) implicit val simpleTimestampTZTypeMapper: JdbcType[Calendar] = new GenericDateJdbcType[Calendar]("timestamptz", java.sql.Types.TIMESTAMP_WITH_TIMEZONE) diff --git a/src/test/scala/com/github/tminglei/slickpg/MyPostgresProfile.scala b/src/test/scala/com/github/tminglei/slickpg/MyPostgresProfile.scala index aaa4ad6a..262ce7ee 100644 --- a/src/test/scala/com/github/tminglei/slickpg/MyPostgresProfile.scala +++ b/src/test/scala/com/github/tminglei/slickpg/MyPostgresProfile.scala @@ -17,7 +17,7 @@ trait MyPostgresProfile extends ExPostgresProfile trait MyAPI extends ExtPostgresAPI with ArrayImplicits with SimpleDateTimeImplicits - with DateTimeImplicits + with Date2DateTimeImplicitsDuration with SimpleJsonImplicits with NetImplicits with LTreeImplicits diff --git a/src/test/scala/com/github/tminglei/slickpg/PgArraySupportSuite.scala b/src/test/scala/com/github/tminglei/slickpg/PgArraySupportSuite.scala index ebedc166..3eab1890 100644 --- a/src/test/scala/com/github/tminglei/slickpg/PgArraySupportSuite.scala +++ b/src/test/scala/com/github/tminglei/slickpg/PgArraySupportSuite.scala @@ -126,7 +126,7 @@ class PgArraySupportSuite extends AnyFunSuite with PostgresContainer { r => assert(List(testRec2) === r) ), // @> - ArrayTests.filter(_.strArr @> Vector("str3")).sortBy(_.id).to[List].result.map( + ArrayTests.filter(_.strArr @> (Vector("str3"): Rep[Vector[String]])).sortBy(_.id).to[List].result.map( r => assert(List(testRec1, testRec2, testRec3) === r) ), ArrayTests.filter(_.mktFinancialProducts @> List(MarketFinancialProduct("product1"))).sortBy(_.id).to[List].result.map( @@ -255,7 +255,7 @@ class PgArraySupportSuite extends AnyFunSuite with PostgresContainer { sqlu"insert into ArrayTest1 values(${b.id}, ${b.bytea}, ${b.uuidArr}, ${b.strArr}, ${b.longArr}, ${b.intArr}, ${b.shortArr}, ${b.floatArr}, ${b.doubleArr}, ${b.boolArr}, ${b.dateArr}, ${b.timeArr}, ${b.tsArr}, ${b.institutionArr})", sql"select * from ArrayTest1 where id = ${b.id}".as[ArrayBean1].head.map( f => { - b.bytea.zip(f.bytea).map(r => assert(r._1 === r._2)) + b.bytea.toSeq.zip(f.bytea.toSeq).map(r => assert(r._1 === r._2)) b.uuidArr.zip(f.uuidArr).map(r => assert(r._1 === r._2)) b.strArr.getOrElse(Nil).zip(f.strArr.getOrElse(Nil)).map(r => assert(r._1 === r._2)) b.longArr.zip(f.longArr).map(r => assert(r._1 === r._2)) diff --git a/src/test/scala/com/github/tminglei/slickpg/PgCompositeSupportSuite.scala b/src/test/scala/com/github/tminglei/slickpg/PgCompositeSupportSuite.scala index 6de40861..2bbbbcd5 100644 --- a/src/test/scala/com/github/tminglei/slickpg/PgCompositeSupportSuite.scala +++ b/src/test/scala/com/github/tminglei/slickpg/PgCompositeSupportSuite.scala @@ -77,7 +77,7 @@ object PgCompositeSupportSuite { } override val api: API = new API {} - val plainImplicits = new API with SimpleArrayPlainImplicits { + object plainImplicits extends API with SimpleArrayPlainImplicits { import utils.PlainSQLUtils._ // to support 'nextArray[T]/nextArrayOption[T]' in PgArraySupport { diff --git a/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala b/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala index 4b90fbec..987f3ecf 100644 --- a/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala +++ b/src/test/scala/com/github/tminglei/slickpg/PgEnumSupportSuite.scala @@ -27,8 +27,8 @@ class PgEnumSupportSuite extends AnyFunSuite with PostgresContainer { def values = _values map (v => (v.toString, v)) toMap } - object Currency extends Enum[Currency] sealed trait Currency extends Currency.Value + object Currency extends Enum[Currency] case object EUR extends Currency case object GBP extends Currency case object USD extends Currency @@ -60,10 +60,10 @@ class PgEnumSupportSuite extends AnyFunSuite with PostgresContainer { implicit val rainbowTypeMapper: JdbcType[Rainbows.Value] = createEnumJdbcType[Rainbows.type]("Rainbow", Rainbows, true) implicit val rainbowListTypeMapper: JdbcType[List[Rainbows.Value]] = createEnumListJdbcType[Rainbows.type]("Rainbow", Rainbows, true) - implicit val weekDayColumnExtensionMethodsBuilder: api.Rep[WeekDays.Value] => EnumColumnExtensionMethods[WeekDays.Value, WeekDays.Value] = createEnumColumnExtensionMethodsBuilder[WeekDays.type](WeekDays) - implicit val weekDayOptionColumnExtensionMethodsBuilder: api.Rep[Option[WeekDays.Value]] => EnumColumnExtensionMethods[WeekDays.Value, Option[WeekDays.Value]] = createEnumOptionColumnExtensionMethodsBuilder[WeekDays.type](WeekDays) - implicit val rainbowColumnExtensionMethodsBuilder: api.Rep[Rainbows.Value] => EnumColumnExtensionMethods[Rainbows.Value, Rainbows.Value] = createEnumColumnExtensionMethodsBuilder[Rainbows.type](Rainbows) - implicit val rainbowOptionColumnExtensionMethodsBuilder: api.Rep[Option[Rainbows.Value]] => EnumColumnExtensionMethods[Rainbows.Value, Option[Rainbows.Value]] = createEnumOptionColumnExtensionMethodsBuilder[Rainbows.type](Rainbows) + implicit def weekDayColumnExtensionMethodsBuilder(rep: Rep[WeekDays.Value]): EnumColumnExtensionMethods[WeekDays.Value, WeekDays.Value] = createEnumColumnExtensionMethodsBuilder[WeekDays.type](WeekDays).apply(rep) + implicit def weekDayOptionColumnExtensionMethodsBuilder(rep: Rep[Option[WeekDays.Value]]): EnumColumnExtensionMethods[WeekDays.Value, Option[WeekDays.Value]] = createEnumOptionColumnExtensionMethodsBuilder[WeekDays.type](WeekDays).apply(rep) + implicit def rainbowColumnExtensionMethodsBuilder(rep: Rep[Rainbows.Value]): EnumColumnExtensionMethods[Rainbows.Value, Rainbows.Value] = createEnumColumnExtensionMethodsBuilder[Rainbows.type](Rainbows).apply(rep) + implicit def rainbowOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Rainbows.Value]]): EnumColumnExtensionMethods[Rainbows.Value, Option[Rainbows.Value]] = createEnumOptionColumnExtensionMethodsBuilder[Rainbows.type](Rainbows).apply(rep) /// custom types of java enums and algebraic data type (ADT) implicit val currencyTypeMapper: JdbcType[Currency] = createEnumJdbcType[Currency]("Currency", _.toString, Currency.values.get(_).get, quoteName = false) @@ -73,12 +73,12 @@ class PgEnumSupportSuite extends AnyFunSuite with PostgresContainer { implicit val genderTypeMapper: JdbcType[Gender] = createEnumJdbcType[Gender]("Gender", _.repr, Gender.fromString, quoteName = false) implicit val genderTypeListMapper: JdbcType[List[Gender]] = createEnumListJdbcType[Gender]("Gender", _.repr, Gender.fromString, quoteName = false) - implicit val currencyColumnExtensionMethodsBuilder: api.Rep[Currency] => EnumColumnExtensionMethods[Currency, Currency] = createEnumColumnExtensionMethodsBuilder[Currency] - implicit val currencyOptionColumnExtensionMethodsBuilder: api.Rep[Option[Currency]] => EnumColumnExtensionMethods[Currency, Option[Currency]] = createEnumOptionColumnExtensionMethodsBuilder[Currency] - implicit val languagesColumnExtensionMethodsBuilder: api.Rep[Languages] => EnumColumnExtensionMethods[Languages, Languages] = createEnumColumnExtensionMethodsBuilder[Languages] - implicit val languagesOptionColumnExtensionMethodsBuilder: api.Rep[Option[Languages]] => EnumColumnExtensionMethods[Languages, Option[Languages]] = createEnumOptionColumnExtensionMethodsBuilder[Languages] - implicit val genderColumnExtensionMethodsBuilder: api.Rep[Gender] => EnumColumnExtensionMethods[Gender, Gender] = createEnumColumnExtensionMethodsBuilder[Gender] - implicit val genderOptionColumnExtensionMethodsBuilder: api.Rep[Option[Gender]] => EnumColumnExtensionMethods[Gender, Option[Gender]] = createEnumOptionColumnExtensionMethodsBuilder[Gender] + implicit def currencyColumnExtensionMethodsBuilder(rep: Rep[Currency]): EnumColumnExtensionMethods[Currency, Currency] = createEnumColumnExtensionMethodsBuilder[Currency].apply(rep) + implicit def currencyOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Currency]]): EnumColumnExtensionMethods[Currency, Option[Currency]] = createEnumOptionColumnExtensionMethodsBuilder[Currency].apply(rep) + implicit def languagesColumnExtensionMethodsBuilder(rep: Rep[Languages]): EnumColumnExtensionMethods[Languages, Languages] = createEnumColumnExtensionMethodsBuilder[Languages].apply(rep) + implicit def languagesOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Languages]]): EnumColumnExtensionMethods[Languages, Option[Languages]] = createEnumOptionColumnExtensionMethodsBuilder[Languages].apply(rep) + implicit def genderColumnExtensionMethodsBuilder(rep: Rep[Gender]): EnumColumnExtensionMethods[Gender, Gender] = createEnumColumnExtensionMethodsBuilder[Gender].apply(rep) + implicit def genderOptionColumnExtensionMethodsBuilder(rep: Rep[Option[Gender]]): EnumColumnExtensionMethods[Gender, Option[Gender]] = createEnumOptionColumnExtensionMethodsBuilder[Gender].apply(rep) } } object MyPostgresProfile1 extends MyPostgresProfile1