Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 3 macro cannot find Writes for Seq[Map[String, T]] #974

Closed
tarmath opened this issue Feb 17, 2024 · 1 comment · Fixed by #993
Closed

Scala 3 macro cannot find Writes for Seq[Map[String, T]] #974

tarmath opened this issue Feb 17, 2024 · 1 comment · Fixed by #993

Comments

@tarmath
Copy link

tarmath commented Feb 17, 2024

Code

import play.api.libs.json._

case class Result(status: String)
object Result {
  implicit val format: OFormat[Result] = Json.format[Result]
}

case class Response(results: Seq[Map[String, Result]])
object Response {
  implicit val format: OFormat[Response] = Json.format[Response]
}

val response = Response(results = Seq(Map("123" -> Result("ok"))))
println(Json.toJson(response))

Scala 2.13.12 (works)

-> % scala-cli -S 2.13.12 playJsonSeqMapMacro.sc
Compiling project (Scala 2.13.12, JVM (17))
Compiled project (Scala 2.13.12, JVM (17))
{"results":[{"123":{"status":"ok"}}]}

Scala 3.3.1 (fails)

-> % scala-cli -S 3.3.1 playJsonSeqMapMacro.sc
Compiling project (Scala 3.3.1, JVM (17))
[error] ./playJsonSeqMapMacro.sc:12:44
[error] Instance not found: play.api.libs.json.Writes[scala.collection.immutable.Seq[scala.collection.immutable.Map[String, playJsonSeqMapMacro_.Result]]]
[error]   implicit val format: OFormat[Response] = Json.format[Response]
[error]                                            ^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.3.1, JVM (17))
Compilation failed
@cchantep
Copy link
Member

scala> summon[Format[Seq[Map[String, Result]]]]
-- [E172] Type Error: ----------------------------------------------------------
1 |summon[Format[Seq[Map[String, Result]]]]
  |                                        ^
  |Ambiguous given instances: both method genericMapWrites in trait DefaultWrites and method mapWrites in trait DefaultWrites match type play.api.libs.json.Writes[A] of parameter x of method summon in object Predef
1 error found

sgodbillon added a commit to sgodbillon/play-json that referenced this issue Mar 3, 2024
…String, T]]

Moved the deprecated method `DefaultWrites.mapWrites` into `LowPriorityWrites` to get rid of the ambiguity.
sgodbillon added a commit to sgodbillon/play-json that referenced this issue Mar 4, 2024
…String, T]]

Moved the deprecated method `DefaultWrites.mapWrites` into `LowPriorityWrites` to get rid of the ambiguity.
sgodbillon added a commit to sgodbillon/play-json that referenced this issue Mar 5, 2024
…String, T]]

Moved the deprecated method `DefaultWrites.mapWrites` into `LowPriorityWrites` to get rid of the ambiguity.
cchantep pushed a commit that referenced this issue Mar 5, 2024
…993)

Moved the deprecated method `DefaultWrites.mapWrites` into `LowPriorityWrites` to get rid of the ambiguity.
mergify bot pushed a commit that referenced this issue Apr 29, 2024
…993)

Moved the deprecated method `DefaultWrites.mapWrites` into `LowPriorityWrites` to get rid of the ambiguity.

(cherry picked from commit a842faf)
mkurz added a commit that referenced this issue Apr 29, 2024
[2.10.x] Fix #974 – Scala 3 macro cannot find Writes for Seq[Map[String, T]] (backport #993) by @sgodbillon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants