upickle
upickle copied to clipboard
Serialize intersection types?
type Autosize = AutosizeSignalRef | AutosizeEnum
given ReadWriter[Autosize] = macroRW[Autosize]
enum Contains :
case content,padding
given ReadWriter[Contains] = macroRW[Contains]
enum AutosizeEnum :
case fit,`fit-x`,`fit-y`,none,pad
given ReadWriter[AutosizeEnum] = macroRW[AutosizeEnum]
case class AutosizeSignalRef (
val contains: Option[Contains] = None,
val resize: Option[Boolean] = None,
val signalRefType: Option[AutosizeEnum] = None,
val signal: Option[String] = None
) derives ReadWriter
case class Root (
autosize: Option[Autosize] = None
) derives ReadWriter
@main def hello_world() =
val auto = AutosizeSignalRef(Some(Contains.content), Some(false) ,Some(AutosizeEnum.`fit-x`), None)
val root = Root(Some(auto))
println( upickle.default.write(root, 2) )
For me, this crashes with;
[error] -- Error: /Users/simon/Code/upickle386/GenModule/src/gen/test1.scala:6:46 ------
[error] 6 |given ReadWriter[Autosize] = macroRW[Autosize]
[error] | ^
[error] |no implicit argument of type deriving.Mirror.Of[quicktype.Autosize] was found for parameter x$1 of method macroRW in trait MacroImplicits
[error] one error found
[error] one error found
Given that this is a new language feature of scala 3, I believe this to be a feature request, as opposed to a bug.
Implement this need to introduce macros. Best situation isMirror in scala compiler support it..
Hmmm... that sounds like the "right" solution is down in the scala compiler itself?
It's something that my hobby project would need, but it's a hobby project, so to be explicit - there's clearly no urgency or obligation to anyone. If there is a "relatively simple" solution sketch in upickle itself someone can set out, I'd be willing to have a go... conditioned on the skill level / time requirements!
To be clear - changing the scala compiler (way) beyond my skillset.
I guess what I'm asking, is whether there is an affirmative action I can / should take, or whether this is one to simply engage patience mode on :-)?