jsoniter-scala icon indicating copy to clipboard operation
jsoniter-scala copied to clipboard

Compilation error during cross builds

Open mijicd opened this issue 5 years ago • 12 comments

I have the following class hierarchy:

import com.github.plokhotnyuk.jsoniter_scala.macros._
import com.github.plokhotnyuk.jsoniter_scala.core._

final case class Container(a: Option[Int], b: Option[String], src: Source)

object Container {
  implicit val codec: JsonValueCodec[Container] =
    JsonCodecMaker.make(CodecMakerConfig.withDiscriminatorFieldName(None))
}

sealed trait Source

object Source {
  case object A extends Source
  case object B extends Source
  case object C extends Source
}

While it seems to pass tests and work for single scala version, trying to do the cross-version publish (or any other cross-version task) fails with:

Cannot evaluate a parameter of the 'make' macro call for type

I know this is a known type of error, but what would be the recommended way to overcome this issue?

Please find a minimal failing example here. Running a simple +publishLocal should fail with the described error.

mijicd avatar Jul 20 '20 13:07 mijicd

As a workaround, please use the JsonCodecMaker.makeWithoutDiscriminator macro call (that is available since v2.6.0) instead of JsonCodecMaker.make(CodecMakerConfig.withDiscriminatorFieldName(None))

plokhotnyuk avatar Jul 20 '20 15:07 plokhotnyuk

@plokhotnyuk makeWithoutDiscriminator worked as a charm! Many thanks for prompt fix! :clap: :tada:

mijicd avatar Jul 20 '20 15:07 mijicd

Reopening because the source of the problem (using of Eval.eval for passing of parameters to the make macro that can be used in the compile-time) is not fixed yet.

The full list of Eval.eval calls used in the jsoniter-scala library are listed here: https://github.com/scalacenter/scala-3-migration-guide/pull/11

plokhotnyuk avatar Jul 20 '20 17:07 plokhotnyuk

Yet another workaround that could help for other configurations of derivation is adding intermediate +compile: image

plokhotnyuk avatar Jul 21 '20 07:07 plokhotnyuk

just encountered this issue during casual publish without compile step before it, and it seems to be linked.

[error] java.lang.AssertionError: assertion failed: pkgClass = package <root>, sym = package com, existing = package com (depth=0)
[error]   protected implicit val ErrorBodyCodec: JsonValueCodec[ErrorBody] = JsonCodecMaker.make(SearchModelConfig)
[error]                                   

But I am using quite old version 2.4. At first I thought it's an issue with SBT, but this is actually jsoniters fault?

Thanks

atais avatar Sep 30 '22 13:09 atais