From ef3971fd2f8cef06a454fdf028f39abd0748a318 Mon Sep 17 00:00:00 2001 From: Lawrence Lin Date: Tue, 6 Oct 2026 21:34:31 -0500 Subject: [PATCH] Fix the OWritesBench compilation on Scala 2 Writes.genericMapWrites and Writes.keyMapWrites were called without type arguments, which fails with a diverging implicit expansion on Scala 2.12 and 2.13, so the benchmarks project did not compile there (Scala 3 was fine). Pass the type arguments explicitly. Also format the file with scalafmt; it had not been formatted since it was added, as validateCode does not check the benchmarks project. --- .../scala/play/api/libs/json/OWritesBench.scala | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/benchmarks/src/main/scala/play/api/libs/json/OWritesBench.scala b/benchmarks/src/main/scala/play/api/libs/json/OWritesBench.scala index 16cafd88..d8617447 100644 --- a/benchmarks/src/main/scala/play/api/libs/json/OWritesBench.scala +++ b/benchmarks/src/main/scala/play/api/libs/json/OWritesBench.scala @@ -13,8 +13,8 @@ class OWritesBench { private val employeeWritesFromFields = new OWrites.OWritesFromFields[Employee] { override def writeFields( - fieldsMap: java.util.LinkedHashMap[String, JsValue], - e: Employee + fieldsMap: java.util.LinkedHashMap[String, JsValue], + e: Employee ): Unit = { fieldsMap.put("employeeNumber", JsNumber(e.employeeNumber)) fieldsMap.put("firstName", JsString(e.firstName)) @@ -42,11 +42,12 @@ class OWritesBench { employeeIdMap = Map( "firstName" -> employee.firstName, - "lastName" -> employee.lastName, - "city" -> employee.city, - "country" -> employee.country) + "lastName" -> employee.lastName, + "city" -> employee.city, + "country" -> employee.country + ) - scoreMap = (1 to 100).map(i => i -> (i / 10D)).toMap + scoreMap = 1.to(100).map(i => i -> (i / 10D)).toMap } // --- @@ -57,9 +58,9 @@ class OWritesBench { @Benchmark def writesFromGenericMap(): JsObject = - Writes.genericMapWrites.writes(employeeIdMap) + Writes.genericMapWrites[String, Map].writes(employeeIdMap) @Benchmark def writesFromKeyMap(): JsObject = - Writes.keyMapWrites.writes(scoreMap) + Writes.keyMapWrites[Int, Double, Map].writes(scoreMap) }