cquiroz / sbt-tzdb

sbt plugin to create custom timezone db files
BSD 3-Clause "New" or "Revised" License
8 stars 13 forks source link

Compilation fails when source is generated with spread operator #270

Closed JamesMcIntosh closed 4 months ago

JamesMcIntosh commented 4 months ago

We have been having intermittent issues with the tzdb plugin where it generates the tzdb_java.scala using the spread operator.

Seems it might be related to: https://github.com/cquiroz/scala-java-time/issues/66

[error] /opt/atlassian/pipelines/agent/build/scala/application/admin/target/scala-2.12/src_managed/main/tzdb/tzdb_java.scala:174:346: illegal start of simple expression                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ^
[error]     val America_Puerto_Rico: scala.scalajs.js.Dynamic = js.Dynamic.literal(("s", -15865), ("w", -15865), ("t", scala.scalajs.js.Array[scala.scalajs.js.Array[Int]](scala.scalajs.js.Array[Int](1899087, 43200, -15865, -14400))), ("l", scala.scalajs.js.Array[scala.scalajs.js.Array[Int]](scala.scalajs.js.Array[Int](1899087, 43200, -15865, -14400), ...(1942123, 0, -14400, -10800), scala.scalajs.js.Array[Int](1945273, 7200, -10800, -14400))), ("r", ...()))
[error]                                                                                                                                                                                                                                                                                                                                                          ^
[error] /opt/atlassian/pipelines/agent/build/scala/application/admin/target/scala-2.12/src_managed/main/tzdb/tzdb_java.scala:175:3: ')' expected but '}' found.
[error]   }

The spread operator is some times even being referenced as the val type.

 val Asia_Qostanay: ... = js.Dynamic.literal(("s", 15268), ("w", 15268), ("t", ...(scala.scalajs.js.Array[Int](1924123, 0, 15268, 14400)

When there is no spread operator it compiles correctly.

    val America_Puerto_Rico: scala.scalajs.js.Dynamic = js.Dynamic.literal(("s", -15865), ("w", -15865), ("t", scala.scalajs.js.Array[scala.scalajs.js.Array[Int]](scala.scalajs.js.Array[Int](1899087, 43200, -15865, -14400))), ("l", scala.scalajs.js.Array[scala.scalajs.js.Array[Int]](scala.scalajs.js.Array[Int](1899087, 43200, -15865, -14400), scala.scalajs.js.Array[Int](1942123, 0, -14400, -10800), scala.scalajs.js.Array[Int](1945273, 7200, -10800, -14400))), ("r", scala.scalajs.js.Array[scala.scalajs.js.Array[Int]]()))

Our build environment is

JDK 11
val scalaVersion = "2.12.12"
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("io.github.cquiroz" % "sbt-tzdb" % "3.0.0")

I have also tried with an older scala-js 1.3.0.

JamesMcIntosh commented 4 months ago

Hi @cquiroz, could you give me a quick point in the right direction to what generates these lines of code? Thanks! James

cquiroz commented 4 months ago

Interesting, I can't easily think why it would do that At any rate the generating code is at https://github.com/cquiroz/kuyfi/blob/master/src/main/scala/kuyfi/TZDBCodeGenerator.scala

JamesMcIntosh commented 4 months ago

Thanks @cquiroz, I looked through the code and also the source for treehugger which is used to do the codegen.

The Type.toString method seems like a likely candidate, if it recurses 50 times then it will return "..."

https://github.com/eed3si9n/treehugger/blob/bf6afbde14956fa6c5a850317ec37cbb934615fa/library/src/main/scala/treehugger/Types.scala#L29

The abstract class Type is a child of the Types trait which has the tostringRecursions count.

I wonder if toString is being called in parallel thus intermittently blowing out the recursive check. I need to check if our build is building TZDB in parallel too as it is contained in two Scala.js modules.

JamesMcIntosh commented 4 months ago

Hi @cquiroz,

The two modules were being generated in parallel each with their own TZDB plugin. I've moved the TZDB generation to a parent CrossProject so it is only generated once, this appears to have fixed the issue. Thanks for such a helpful project and for pointing me in the right direction for the codegen!

Many thanks James

cquiroz commented 4 months ago

Oh that's interesting, would it be possible to add a comment to the README about this?

JamesMcIntosh commented 4 months ago

I've submitted a PR which makes a basic dependant configuration suggestion, feel free to change it round as there's a few ways to write that up. https://github.com/cquiroz/sbt-tzdb/pull/271