From 60be6be1ae17e3bef5f863119d3ab219ba093d2d Mon Sep 17 00:00:00 2001 From: Martin Welgemoed Date: Thu, 22 Jun 2023 17:00:06 +0200 Subject: [PATCH] Failing test for the issue --- .../io/sphere/json/generic/JSONMacros.scala | 1 + .../io/sphere/json/AnotherFileExample.scala | 17 +++++++++++++++++ .../io/sphere/json/MultiFileJSONSpec.scala | 17 +++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 json/json-derivation/src/test/scala/io/sphere/json/AnotherFileExample.scala create mode 100644 json/json-derivation/src/test/scala/io/sphere/json/MultiFileJSONSpec.scala diff --git a/json/json-derivation/src/main/scala/io/sphere/json/generic/JSONMacros.scala b/json/json-derivation/src/main/scala/io/sphere/json/generic/JSONMacros.scala index e7d6a60a..9f09fe63 100644 --- a/json/json-derivation/src/main/scala/io/sphere/json/generic/JSONMacros.scala +++ b/json/json-derivation/src/main/scala/io/sphere/json/generic/JSONMacros.scala @@ -167,6 +167,7 @@ private[generic] object JSONMacros { ) else { val subtypes = collectKnownSubtypes(c)(symbol) + c.info(c.enclosingPosition, symbol.fullName + " Subtypes: " + subtypes.mkString(", "), true) val idents = Ident(symbol.name) :: subtypes.map { s => if (s.isModuleClass) New(TypeTree(s.asClass.toType)) else Ident(s.name) }.toList diff --git a/json/json-derivation/src/test/scala/io/sphere/json/AnotherFileExample.scala b/json/json-derivation/src/test/scala/io/sphere/json/AnotherFileExample.scala new file mode 100644 index 00000000..711512cb --- /dev/null +++ b/json/json-derivation/src/test/scala/io/sphere/json/AnotherFileExample.scala @@ -0,0 +1,17 @@ +package io.sphere.json + +object AnotherFileExample { + sealed abstract class Bug { + def name: String + def legs: Int + } + abstract class Insect extends Bug { + def legs = 6 + } + case class Spider(name: String) extends Bug { + def legs = 8 + } + + case class Ant(name: String) extends Insect + case class Grasshopper(name: String) extends Insect +} diff --git a/json/json-derivation/src/test/scala/io/sphere/json/MultiFileJSONSpec.scala b/json/json-derivation/src/test/scala/io/sphere/json/MultiFileJSONSpec.scala new file mode 100644 index 00000000..46a1d68c --- /dev/null +++ b/json/json-derivation/src/test/scala/io/sphere/json/MultiFileJSONSpec.scala @@ -0,0 +1,17 @@ +package io.sphere.json + +import io.sphere.json.generic._ +import org.scalatest.OptionValues +import org.scalatest.matchers.must.Matchers +import org.scalatest.wordspec.AnyWordSpec +import cats.data.Validated.Valid +import io.sphere.json.AnotherFileExample._ +class MultiFileJSONSpec extends AnyWordSpec with Matchers with OptionValues { + "deriveJSON" should { + "handle classes in another file correctly" in { + implicit val bugJSON = deriveJSON[Bug] + val a = Ant("C. ligniperda") + fromJSON[Bug](toJSON[Bug](a)) must equal(Valid(a)) + } + } +}