Skip to content

DefaultValues macro option ignored by Scala 3 version #1146

@migesok

Description

@migesok

Play JSON Version (2.5.x / etc)

2.10.6, 3.0.4, probably any in between

API (Scala / Java / Neither / Both)

Scala

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

macOS 14.7.1 M1

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment Temurin-17.0.5+8 (build 17.0.5+8)
OpenJDK 64-Bit Server VM Temurin-17.0.5+8 (build 17.0.5+8, mixed mode)

Library Dependencies

Scala 2.13.6, Scala 3.3.5

Expected Behavior

This should behave the same way on both Scala 2.13 and Scala 3:

import play.api.libs.json.Json

final case class Data(field: Int = 1)

val reads = Json.reads[Data]

println(reads.reads(Json.obj()))

Actual Behavior

On Scala 2:

JsError(List((/field,List(JsonValidationError(List(error.path.missing),List())))))

On Scala 3:

JsSuccess(Data(1),)

Notes

It appears that DefaultValues macro option is disabled by default in the Scala 2 version but not handled at all in the Scala 3 version. At least I haven't found any code touching it the Scala 3 macro.

Such a change in behaviour could lead to unexpected bugs. I noticed it when I tried to introduce Scala 3 cross-compilation in a library and one of the JSON format tests started to fail because it had format.orElse(anotherFormat) and format never failed in Scala 3 version due to different handling of default values.

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