From d786717b82114717c5af517fbc8acf2a2b103b94 Mon Sep 17 00:00:00 2001 From: Dawid Dworak Date: Thu, 15 Dec 2022 09:34:04 +0100 Subject: [PATCH 1/4] Run tests on JDK17 --- .github/workflows/ci.yml | 2 +- project/Build.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25d7fc6ba..cef6a4d64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: matrix: os: [ubuntu-latest] scala: [2.13.10, 2.12.17] - java: [graalvm-ce-java11@21.1.0] + java: [graalvm-ce-java11@21.1.0, openjdk@1.17] runs-on: ${{ matrix.os }} steps: - name: Checkout current branch (full) diff --git a/project/Build.scala b/project/Build.scala index 6e9038456..b50524fcf 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -92,7 +92,7 @@ object Build extends BuildDef { githubWorkflowEnv ++= Map( "REDIS_VERSION" -> "6.2.6", ), - githubWorkflowJavaVersions := Seq("graalvm-ce-java11@21.1.0"), + githubWorkflowJavaVersions := Seq("graalvm-ce-java11@21.1.0", "openjdk@1.17"), githubWorkflowBuildPreamble ++= Seq( WorkflowStep.Use( "actions", "cache", "v2", From c5990d248978f3f2a24863984e62b47df92e5633 Mon Sep 17 00:00:00 2001 From: Dawid Dworak Date: Thu, 15 Dec 2022 16:18:46 +0100 Subject: [PATCH 2/4] Fix compilation under JDK17 --- .../com/avsystem/commons/macros/MacroCommons.scala | 13 +++++++++++-- .../avsystem/commons/redis/commands/streams.scala | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/commons-macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala b/commons-macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala index 6b5f6a5fe..ba0760beb 100644 --- a/commons-macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala +++ b/commons-macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala @@ -1051,7 +1051,7 @@ trait MacroCommons extends CompatMacroCommons { bundle => actualParamType(param.typeSignature) def actualParamType(tpe: Type): Type = tpe match { - case TypeRef(_, s, List(arg)) if s == definitions.RepeatedParamClass => + case TypeRef(_, s, List(arg)) if s == definitions.RepeatedParamClass || s == definitions.JavaRepeatedParamClass => getType(tq"$ScalaPkg.Seq[$arg]") case TypeRef(_, s, List(arg)) if s == definitions.ByNameParamClass => arg @@ -1409,10 +1409,17 @@ trait MacroCommons extends CompatMacroCommons { bundle => } } - def determineTypeParams(undetTpe: Type, detTpe: Type, typeParams: List[Symbol]): Option[List[Type]] = { + def determineTypeParams(undetTpe: Type, detTpe: Type, typeParams: List[Symbol], debug: Boolean = false): Option[List[Type]] = { val methodName = c.freshName(TermName("m")) val typeDefs = typeParams.map(typeSymbolToTypeDef(_, forMethod = true)) + if(debug) { + q""" + def $methodName[..$typeDefs](f: ${treeForType(undetTpe)} => $UnitCls): $UnitCls = () + $methodName((_: $detTpe) => ()) + """.debug("") + } + val tree = typecheck( q""" def $methodName[..$typeDefs](f: ${treeForType(undetTpe)} => $UnitCls): $UnitCls = () @@ -1420,6 +1427,8 @@ trait MacroCommons extends CompatMacroCommons { bundle => """, silent = true ) + if(debug) println(tree) + tree match { case Block(_, Apply(TypeApply(_, args), _)) => Some(args.map(_.tpe)) case Block(_, Apply(_, _)) => Some(Nil) diff --git a/commons-redis/src/main/scala/com/avsystem/commons/redis/commands/streams.scala b/commons-redis/src/main/scala/com/avsystem/commons/redis/commands/streams.scala index 16e44e6a3..ca1ac88b9 100644 --- a/commons-redis/src/main/scala/com/avsystem/commons/redis/commands/streams.scala +++ b/commons-redis/src/main/scala/com/avsystem/commons/redis/commands/streams.scala @@ -398,7 +398,7 @@ object XEntryId { CommandArg((enc, eid) => enc.add(eid.toString)) } -case class XEntry[Record](id: XEntryId, data: Record) +case class XEntry[Rec](id: XEntryId, data: Rec) case class XMaxlen(maxlen: Long, approx: Boolean = true) object XMaxlen { From 777e2c4ef0c5be2d55c963561f945958434534f4 Mon Sep 17 00:00:00 2001 From: Dawid Dworak Date: Fri, 16 Dec 2022 09:47:24 +0100 Subject: [PATCH 3/4] Separate API reflection test for JDK17 --- .../commons/rpc/ApiReflectionTest.scala | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/commons-core/src/test/scala/com/avsystem/commons/rpc/ApiReflectionTest.scala b/commons-core/src/test/scala/com/avsystem/commons/rpc/ApiReflectionTest.scala index 4640437df..bd03f2693 100644 --- a/commons-core/src/test/scala/com/avsystem/commons/rpc/ApiReflectionTest.scala +++ b/commons-core/src/test/scala/com/avsystem/commons/rpc/ApiReflectionTest.scala @@ -75,7 +75,8 @@ class SimpleApi { } class ApiReflectionTest extends AnyFunSuite { - test("String API") { + test("String API JDK11") { + assume(System.getProperty("java.specification.version") == "11") assert(ApiInfo.materialize[String].repr == """String { | def length(): Int @@ -140,6 +141,79 @@ class ApiReflectionTest extends AnyFunSuite { ) } + test("String API JDK17") { + assume(System.getProperty("java.specification.version") == "17") + assert(ApiInfo.materialize[String].repr == + """String { + | def length(): Int + | def isEmpty(): Boolean + | def charAt(x$1: Int): Char + | def codePointAt(x$1: Int): Int + | def codePointBefore(x$1: Int): Int + | def codePointCount(x$1: Int, x$2: Int): Int + | def offsetByCodePoints(x$1: Int, x$2: Int): Int + | def getChars(x$1: Int, x$2: Int, x$3: Array[Char], x$4: Int): Unit + | def getBytes(x$1: Int, x$2: Int, x$3: Array[Byte], x$4: Int): Unit + | def getBytes(x$1: String): Array[Byte] + | def getBytes(x$1: java.nio.charset.Charset): Array[Byte] + | def getBytes(): Array[Byte] + | def contentEquals(x$1: StringBuffer): Boolean + | def contentEquals(x$1: CharSequence): Boolean + | def equalsIgnoreCase(x$1: String): Boolean + | def compareTo(x$1: String): Int + | def compareToIgnoreCase(x$1: String): Int + | def regionMatches(x$1: Int, x$2: String, x$3: Int, x$4: Int): Boolean + | def regionMatches(x$1: Boolean, x$2: Int, x$3: String, x$4: Int, x$5: Int): Boolean + | def startsWith(x$1: String, x$2: Int): Boolean + | def startsWith(x$1: String): Boolean + | def endsWith(x$1: String): Boolean + | def indexOf(x$1: Int): Int + | def indexOf(x$1: Int, x$2: Int): Int + | def lastIndexOf(x$1: Int): Int + | def lastIndexOf(x$1: Int, x$2: Int): Int + | def indexOf(x$1: String): Int + | def indexOf(x$1: String, x$2: Int): Int + | def lastIndexOf(x$1: String): Int + | def lastIndexOf(x$1: String, x$2: Int): Int + | def substring(x$1: Int): String + | def substring(x$1: Int, x$2: Int): String + | def subSequence(x$1: Int, x$2: Int): CharSequence + | def concat(x$1: String): String + | def replace(x$1: Char, x$2: Char): String + | def matches(x$1: String): Boolean + | def contains(x$1: CharSequence): Boolean + | def replaceFirst(x$1: String, x$2: String): String + | def replaceAll(x$1: String, x$2: String): String + | def replace(x$1: CharSequence, x$2: CharSequence): String + | def split(x$1: String, x$2: Int): Array[String] + | def split(x$1: String): Array[String] + | def toLowerCase(x$1: java.util.Locale): String + | def toLowerCase(): String + | def toUpperCase(x$1: java.util.Locale): String + | def toUpperCase(): String + | def trim(): String + | def strip(): String + | def stripLeading(): String + | def stripTrailing(): String + | def isBlank(): Boolean + | def lines(): java.util.stream.Stream[String] + | def indent(x$1: Int): String + | def stripIndent(): String + | def translateEscapes(): String + | def transform[R](x$1: java.util.function.Function[_ >: String, _ <: R]): R + | def chars(): java.util.stream.IntStream + | def codePoints(): java.util.stream.IntStream + | def toCharArray(): Array[Char] + | def formatted(x$1: Seq[AnyRef]): String + | def intern(): String + | def repeat(x$1: Int): String + | def describeConstable(): java.util.Optional[String] + | def resolveConstantDesc(x$1: java.lang.invoke.MethodHandles.Lookup): String + | final def +(x$1: Any): String + |}""".stripMargin + ) + } + test("Simple API") { assert(ApiInfo.materialize[SimpleApi].repr == """com.avsystem.commons.rpc.SimpleApi { From d930c98f8e8d0b2803baabd7d30bbf834886e544 Mon Sep 17 00:00:00 2001 From: Dawid Dworak Date: Fri, 16 Dec 2022 11:11:16 +0100 Subject: [PATCH 4/4] Rmemove debug code --- .../com/avsystem/commons/macros/MacroCommons.scala | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/commons-macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala b/commons-macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala index ba0760beb..e4d106014 100644 --- a/commons-macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala +++ b/commons-macros/src/main/scala/com/avsystem/commons/macros/MacroCommons.scala @@ -1409,17 +1409,10 @@ trait MacroCommons extends CompatMacroCommons { bundle => } } - def determineTypeParams(undetTpe: Type, detTpe: Type, typeParams: List[Symbol], debug: Boolean = false): Option[List[Type]] = { + def determineTypeParams(undetTpe: Type, detTpe: Type, typeParams: List[Symbol]): Option[List[Type]] = { val methodName = c.freshName(TermName("m")) val typeDefs = typeParams.map(typeSymbolToTypeDef(_, forMethod = true)) - if(debug) { - q""" - def $methodName[..$typeDefs](f: ${treeForType(undetTpe)} => $UnitCls): $UnitCls = () - $methodName((_: $detTpe) => ()) - """.debug("") - } - val tree = typecheck( q""" def $methodName[..$typeDefs](f: ${treeForType(undetTpe)} => $UnitCls): $UnitCls = () @@ -1427,8 +1420,6 @@ trait MacroCommons extends CompatMacroCommons { bundle => """, silent = true ) - if(debug) println(tree) - tree match { case Block(_, Apply(TypeApply(_, args), _)) => Some(args.map(_.tpe)) case Block(_, Apply(_, _)) => Some(Nil)