sbt / contraband

http://www.scala-sbt.org/contraband/
Other
69 stars 22 forks source link

Identifier conflict on "js" field when generating JSON codec with sjson new #131

Closed wsargent closed 5 years ago

wsargent commented 5 years ago

In the sjson generation code, the pattern match uses the identifier of js, which can conflict with the type field if it is also named js:

import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait DeviceInfoFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val DeviceInfoFormat: JsonFormat[DeviceInfo] = new JsonFormat[DeviceInfo] {
  override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): DeviceInfo = {
    jsOpt match {
      case Some(js) =>
      unbuilder.beginObject(js)
      val js = unbuilder.readField[Option[Boolean]]("js")

      case None =>
        deserializationError("Expected JsObject but found None")
    }
  }

results in

[error] <snip>/codecs/DeviceInfoFormats.scala:13:29: type mismatch;
[error]  found   : js.type (with underlying type Option[Boolean])
[error]  required: J
[error]       unbuilder.beginObject(js)
[error]                             ^

Looks like it's at https://github.com/sbt/contraband/blob/master/library/src/main/scala/sbt/contraband/CodecCodeGen.scala#L66