Skip to content

Scala 3: Add support for literal-based singleton types #1161

@tarmath

Description

@tarmath

Add support for SIP-23 - Literal-based singleton types

play-json 3.0.4
JDK 17

Reproducible Test Case

package play.api.libs.json

object TestSingletonTypes {
  case class CaseClassWithSingleton(
    singleton: "singleton"
  )  

  object CaseClassWithSingleton {
    implicit val format: Format[CaseClassWithSingleton] = Json.format[CaseClassWithSingleton]
  }
}

Result

Fails to compile with:

[error] -- Error: /Users/mpichette/src/git/oss/play-json/play-json/shared/src/test/scala-3/play/api/libs/json/TestSingletonTypes.scala:13:60 
[error] 13 |    implicit val format: Format[CaseClassWithSingleton] = Json.format[CaseClassWithSingleton]
[error]    |                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |                    Instance not found: play.api.libs.json.Reads[String]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions