2

I wan't to combine two macro annotations. It compiles perfectly fine but trying to use any method on companion object gives

java.lang.NoClassDefFoundError: Test$

If used separately macro annotations works fine.

@JsonCodec:

import io.circe.generic.JsonCodec
@JsonCodec
case class Test(a: Int)

println(Test.decodeTest.hashCode())

>> 161960012

@Lenses

import monocle.macros.Lenses
@Lenses("_")
case class Test(a: Int)

println(Test._a.hashCode())

>> 1685232414

But if I try to combine it

import io.circe.generic.JsonCodec
import monocle.macros.Lenses
@Lenses("_")
@JsonCodec
case class Test(a: Int)

>> Done compiling.
>> [E] Exception in thread "main" java.lang.NoClassDefFoundError: Test$
>> [E]  at Main$.main(Main.scala:39)
>> [E]  at Main.main(Main.scala)
>> [E] Caused by: java.lang.ClassNotFoundException: Test$
>> [E]  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
>> [E]  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
>> [E]  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
>> [E]  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
>> [E]  ... 2 more

It will fail at runtime.

Any way to fix it or is it just limitation of macro annotations usage?

UPD: Defining companion object workaround works.

import io.circe.generic.JsonCodec
import monocle.macros.Lenses

@JsonCodec @Lenses("_") case class Test(a: Int)
object Test
  • 3
    Looks like it might be a bug in one of the libraries or Scala macro implementation but defining an empty companion object seems to work around it: `@Lenses("_") @JsonCodec case class Test(a: Int); object Test` – Olli Helenius Oct 25 '18 at 07:43
  • 3
    https://stackoverflow.com/questions/39741393/multiple-scala-macro-annotation-does-not-generate-class-file – Dmytro Mitin Oct 25 '18 at 08:25

1 Answers1

0

Looks like macro annotations limitation. Companion object workaround works

@JsonCodec @Lenses("_") case class Test(a: Int)
object Test