Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated formatter derivation fails for case classes that extend a trait (or abstract class). #35

Open
crimzie opened this issue Apr 23, 2018 · 1 comment

Comments

@crimzie
Copy link

crimzie commented Apr 23, 2018

import net.jcazevedo.moultingyaml._
import net.jcazevedo.moultingyaml.DefaultYamlProtocol._

abstract class Symbolic {
  val id: String
  val name: Map[String, String]
  val description: Map[String, String]
  val symbol: Option[Char]
  val iterator: Iterator[Symbolic]
}

case class Infl(
    id: String,
    name: Map[String, String],
    description: Map[String, String],
    symbol: Option[Char])
  extends Symbolic {
  override val iterator: Iterator[Symbolic] = Iterator.empty
}

object Infl {
  implicit val format: YamlFormat[Infl] = yamlFormat4(apply)
}

case class Cat(
    id: String,
    name: Map[String, String],
    description: Map[String, String],
    inflections: Seq[Infl])
  extends Symbolic {
  override val symbol: Option[Char] = None
  override val iterator: Iterator[Symbolic] = inflections.iterator
}

object Cat {
  implicit val format: YamlFormat[Cat] = yamlFormat4(apply)

  def fromYaml(res: String): Cat = {
    scala.io.Source.fromResource(res).mkString.parseYaml.convertTo[Cat]
  }
}

fails with

[info] com.crimzie.uni.model.DocsTests *** ABORTED ***
[info]   java.lang.ExceptionInInitializerError:
[info]   at com.crimzie.uni.model.Cat$.<init>(docs.scala:43)
[info]   at com.crimzie.uni.model.Cat$.<clinit>(docs.scala)
[info]   at com.crimzie.uni.model.DocsTests.$anonfun$new$2(DocsTests.scala:10)
[info]   at scala.util.Try$.apply(Try.scala:209)
[info]   at com.crimzie.uni.model.DocsTests.$anonfun$new$1(DocsTests.scala:9)
[info]   at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
[info]   at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
[info]   at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:22)
[info]   at org.scalatest.Transformer.apply(Transformer.scala:20)
[info]   ...
[info]   Cause: java.lang.RuntimeException: Case class com.crimzie.uni.model.Infl declares additional fields
[info]   at scala.sys.package$.error(package.scala:27)
[info]   at net.jcazevedo.moultingyaml.ProductFormats.fieldInfo(ProductFormats.scala:1052)
[info]   at net.jcazevedo.moultingyaml.ProductFormats.yamlFormat4(ProductFormats.scala:44)
[info]   at net.jcazevedo.moultingyaml.ProductFormats.yamlFormat4$(ProductFormats.scala:41)
[info]   at net.jcazevedo.moultingyaml.DefaultYamlProtocol$.yamlFormat4(DefaultYamlProtocol.scala:13)
[info]   at com.crimzie.uni.model.Infl$.<init>(docs.scala:59)
[info]   at com.crimzie.uni.model.Infl$.<clinit>(docs.scala)
[info]   at com.crimzie.uni.model.Cat$.<init>(docs.scala:43)
[info]   at com.crimzie.uni.model.Cat$.<clinit>(docs.scala)
[info]   at com.crimzie.uni.model.DocsTests.$anonfun$new$2(DocsTests.scala:10)
[info]   ...
[error] java.lang.NoClassDefFoundError: Could not initialize class com.crimzie.uni.model.Cat$
[error] 	at com.crimzie.uni.model.Docs$.<init>(docs.scala:83)
[error] 	at com.crimzie.uni.model.Docs$.<clinit>(docs.scala)
[error] 	at com.crimzie.uni.model.categories.Fnction$Noun$.<init>(Fnction.scala:10)
[error] 	at com.crimzie.uni.model.categories.Fnction$Noun$.<clinit>(Fnction.scala)
[error] 	at com.crimzie.uni.model.structures.Word$.apply$default$1(member.scala:14)
[error] 	at com.crimzie.uni.model.structures.ClauseTreeTests.$anonfun$new$1(ClauseTreeTests.scala:11)
[error] 	at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
[error] 	at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
[error] 	at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
[error] 	at org.scalatest.Transformer.apply(Transformer.scala:22)
[error] 	at org.scalatest.Transformer.apply(Transformer.scala:20)
[error] 	at org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1682)
[error] 	at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
[error] 	at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
[error] 	at org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1685)
[error] 	at org.scalatest.FlatSpecLike.invokeWithFixture$1(FlatSpecLike.scala:1680)
[error] 	at org.scalatest.FlatSpecLike.$anonfun$runTest$1(FlatSpecLike.scala:1692)
[error] 	at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
[error] 	at org.scalatest.FlatSpecLike.runTest(FlatSpecLike.scala:1692)
[error] 	at org.scalatest.FlatSpecLike.runTest$(FlatSpecLike.scala:1674)
[error] 	at org.scalatest.FlatSpec.runTest(FlatSpec.scala:1685)
[error] 	at org.scalatest.FlatSpecLike.$anonfun$runTests$1(FlatSpecLike.scala:1750)
[error] 	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:396)
[error] 	at scala.collection.immutable.List.foreach(List.scala:389)
[error] 	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
[error] 	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:373)
[error] 	at org.scalatest.SuperEngine.$anonfun$runTestsInBranch$1(Engine.scala:410)
[error] 	at scala.collection.immutable.List.foreach(List.scala:389)
[error] 	at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
[error] 	at org.scalatest.SuperEngine.runTestsInBranch(Engine.scala:379)
[error] 	at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:461)
[error] 	at org.scalatest.FlatSpecLike.runTests(FlatSpecLike.scala:1750)
[error] 	at org.scalatest.FlatSpecLike.runTests$(FlatSpecLike.scala:1749)
[error] 	at org.scalatest.FlatSpec.runTests(FlatSpec.scala:1685)
[error] 	at org.scalatest.Suite.run(Suite.scala:1147)
[error] 	at org.scalatest.Suite.run$(Suite.scala:1129)
[error] 	at org.scalatest.FlatSpec.org$scalatest$FlatSpecLike$$super$run(FlatSpec.scala:1685)
[error] 	at org.scalatest.FlatSpecLike.$anonfun$run$1(FlatSpecLike.scala:1795)
[error] 	at org.scalatest.SuperEngine.runImpl(Engine.scala:521)
[error] 	at org.scalatest.FlatSpecLike.run(FlatSpecLike.scala:1795)
[error] 	at org.scalatest.FlatSpecLike.run$(FlatSpecLike.scala:1793)
[error] 	at org.scalatest.FlatSpec.run(FlatSpec.scala:1685)
[error] 	at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:314)
[error] 	at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:507)
[error] 	at sbt.TestRunner.runTest$1(TestFramework.scala:106)
[error] 	at sbt.TestRunner.run(TestFramework.scala:117)
[error] 	at sbt.TestFramework$$anon$2$$anonfun$$lessinit$greater$1.$anonfun$apply$1(TestFramework.scala:262)
[error] 	at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:233)
[error] 	at sbt.TestFramework$$anon$2$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:262)
[error] 	at sbt.TestFramework$$anon$2$$anonfun$$lessinit$greater$1.apply(TestFramework.scala:262)
[error] 	at sbt.TestFunction.apply(TestFramework.scala:271)
[error] 	at sbt.Tests$.$anonfun$toTask$1(Tests.scala:281)
[error] 	at sbt.std.Transform$$anon$3.$anonfun$apply$2(System.scala:46)
[error] 	at sbt.std.Transform$$anon$4.work(System.scala:66)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] 	at sbt.Execute.work(Execute.scala:271)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] 	at java.lang.Thread.run(Thread.java:748)
[error] (Test / executeTests) java.lang.NoClassDefFoundError: Could not initialize class com.crimzie.uni.model.Cat$
@crimzie crimzie changed the title Automated formatter derivation fails for case classes that extend a trait. Automated formatter derivation fails for case classes that extend a trait (or abstract class). Apr 23, 2018
@gwang555
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants