typelevel / cats-tagless

Library of utilities for tagless final encoded algebras
https://typelevel.org/cats-tagless/
Apache License 2.0
314 stars 41 forks source link

Having multiple annotations on a trait without a companion throws at runtime #125

Open kubukoz opened 4 years ago

kubukoz commented 4 years ago
import cats.tagless.implicits._
import cats.tagless.finalAlg
import cats.tagless.autoFunctorK
import cats.arrow.FunctionK

//or autoFunctorK + autoInstrument, or finalAlg + autoInstrument, etc.
@autoFunctorK
@finalAlg
trait Foo[F[_]] {
  def bar(a: Int): F[Int]
}

//object Foo {}

object Main extends App {
  val foo: Foo[cats.Id] = _ => 42

  println(foo.mapK(FunctionK.id))
}

This will result in java.lang.NoClassDefFoundError: Foo$. Uncommenting the companion object fixes things.

joroKr21 commented 4 years ago

Ha, interesting. I guess the two annotations are competing on adding the companion object 🤔

dispalt commented 4 years ago

yup ran into this a bunch before, real annoying could never figure out a workaround.

joroKr21 commented 4 years ago

But the tests are full of such algebras with two annotations and no companion objects: https://github.com/typelevel/cats-tagless/blob/master/tests/src/test/scala/cats/tagless/tests/autoFunctorKTests.scala

Could it be something related to incremental compilation? Can you try to clean and compile again?

dispalt commented 4 years ago

I forgot to mention but it works when its within another object, another reason why it was so annoying to figure it out. If you move one of those traits with two annotations to the top level of the file, it won't work, IIRC.

danslapman commented 3 years ago

Good old bug: https://github.com/scalameta/scalameta/issues/1046, this is to be fixed in scalac (paradise was merged in 2.13)

joroKr21 commented 3 years ago

Would this fix the problem? scala/scala#9555