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

Add test for constructing Writes with case class #1040

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

levinson
Copy link

@levinson levinson commented May 11, 2024

Pull Request Checklist

  • Have you read through the contributor guidelines?
  • Have you squashed your commits?
  • Have you added copyright headers to new files? N/A
  • Have you updated the documentation? N/A
  • Have you added tests for any changed functionality? N/A

Background

The syntax in the README for constructing Writes fails to compile in Scala 3:

[error] -- [E007] Type Mismatch Error:
[error] 189 |        ) (unlift(Location.unapply))
[error]     |                  ^^^^^^^^^^^^^^^^
[error]     |                  Found:    Location
[error]     |                  Required: Option[Any]

This is due to the following change to case class unapply: https://docs.scala-lang.org/scala3/guides/migration/incompat-other-changes.html#explicit-call-to-unapply

Following the guidance from the migration guide pattern binding is used instead of call to unapply.

This PR fixes #1039 by updating the syntax in README to support Scala 3 and add new unit test.

@levinson levinson force-pushed the constructing-writes-scala3-compile-bug branch 4 times, most recently from 1f5807a to da3e62e Compare May 13, 2024 14:37
Updated syntax in README to support Scala 3
@levinson levinson force-pushed the constructing-writes-scala3-compile-bug branch from da3e62e to 4aee6a7 Compare May 13, 2024 15:02

val serialized = Json.stringify(Json.toJson(location))
serialized.mustEqual("""{"lat":1.1,"long":2.2}""")
Json.fromJson[Location](Json.parse(serialized)).mustEqual(JsSuccess(location))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required to test Writes

@@ -246,19 +246,28 @@ import play.api.libs.functional.syntax._
implicit val locationWrites: Writes[Location] = (
(JsPath \ "lat").write[Double] and
(JsPath \ "long").write[Double]
)(unlift(Location.unapply))
)(location => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Snippets should show use cases for both versions

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 this pull request may close these issues.

Constructing Writes fail to compile with Scala 3
2 participants