stanch / reftree

Automatically generated diagrams and animations for Scala data structures
http://stanch.github.io/reftree/
GNU General Public License v3.0
587 stars 36 forks source link

Rename doesn't work when composing multiple case classes #11

Closed hejfelix closed 7 years ago

hejfelix commented 7 years ago

So I'm generating these two images from the code below:

"integer.png" integer

"application_with_integer" application_with_integer

In the first case, my integer case class is correctly renamed to bob. In the second case, no renaming happens.

implicit val tint: ToRefTree.DerivationConfig[Integer] =
  ToRefTree
    .DerivationConfig[Integer]
    .rename("bob")
    .omitField("i")

val renderer = Renderer(
  renderingOptions = RenderingOptions(density = 75),
  animationOptions = AnimationOptions(interpolationDuration = 3.seconds, framesPerSecond = 1),
  directory = Paths.get("images")
)
renderer.render("application_with_integer", Diagram(Application(Integer(42), Identifier("x"))))
renderer.render("integer", Diagram(Integer(42)))

I am not sure if I am using the API correctly, but I can see that the "i" field is omitted in both cases, i.e. some of the options must be picked up in both cases.

stanch commented 7 years ago

Thanks! Reproduced like so:

sealed trait AST
case class Integer(i: Int) extends AST
case class Application(tree: AST, method: String) extends AST

implicit val c = ToRefTree.DerivationConfig[Integer].rename("Bob").omitField("i")

render(Application(Integer(8), "x"))

Probably something is wrong in the coproduct derivation code.

stanch commented 7 years ago

Actually, render(Integer(8): AST) is enough to reproduce this.

stanch commented 7 years ago

@hejfelix Just released 1.1.0-20170618 with a fix, could you try it?

hejfelix commented 7 years ago

fixed 👍