Skip to content

Commit

Permalink
Merge pull request #163 from eed3si9n/wip/stackoverflow
Browse files Browse the repository at this point in the history
Fixes stackoverflow
  • Loading branch information
eed3si9n authored Jan 18, 2022
2 parents bcf3e9e + 3957892 commit e2ffdea
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
11 changes: 9 additions & 2 deletions library/src/main/scala/sbt/contraband/CodecCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,15 @@ class CodecCodeGen(
private def getRequiredFormats(s: Document, d: TypeDefinition): List[String] = {
val typeFormats =
d match {
case _: EnumTypeDefinition => Nil
case c: RecordLikeDefinition => c.fields flatMap { f => lookupFormats(s, f.fieldType) }
case _: EnumTypeDefinition => Nil
case c: RecordLikeDefinition =>
c.fields flatMap { f =>
// if the field type is d, we don't need additional codec
lookupDefinition(s, f.fieldType.name) match {
case Some((s1, d1)) if s1 == s && d1 == d => Nil
case _ => lookupFormats(s, f.fieldType)
}
}
}
typeFormats ++ codecParents
}
Expand Down
8 changes: 8 additions & 0 deletions plugin/src/sbt-test/sbt-contraband/recursive-type/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sbt.contraband._

lazy val root = (project in file("."))
.enablePlugins(ContrabandPlugin, JsonCodecPlugin)
.settings(
name := "example",
libraryDependencies += "com.eed3si9n" %% "sjson-new-scalajson" % contrabandSjsonNewVersion.value,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("org.scala-sbt" % "sbt-contraband" % pluginVersion)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sbt.internal.graph
@target(Scala)
@codecPackage("sbt.internal.graph.codec")
@fullCodec("JsonProtocol")

type ModuleModel {
text: String!
children: [sbt.internal.graph.ModuleModel]
}
1 change: 1 addition & 0 deletions plugin/src/sbt-test/sbt-contraband/recursive-type/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> compile

0 comments on commit e2ffdea

Please sign in to comment.