monadless icon indicating copy to clipboard operation
monadless copied to clipboard

Bug when scala-logging

Open orium opened this issue 7 years ago • 2 comments

Monadless Version: 0.0.13 Scala-Logging Version: 3.9.0

There seems to be a problem when using monadless and scala-logging.

If you try to compile

import cats.effect.IO
import com.typesafe.scalalogging.StrictLogging
import io.monadless.cats.MonadlessMonad

object Foo extends StrictLogging {
  val monadlessIO: MonadlessMonad[IO] = io.monadless.cats.MonadlessMonad[IO]()
  import monadlessIO._

  lift {
    val opt = Some("foo")
    val aString = ""

    logger.error(s"$opt $aString")
  }
}

you will get this error:

[error] /tmp/orium/hunt-monadless-bug/service/src/main/scala/NewAssetProcessor.scala:9:8: Can't typecheck the monadless transformation. Please file a bug report with this error and your `Monadless` instance. 
[error] Failure: not found: value ClassTag
[error] Tree: Foo.this.monadlessIO.apply({
[error]   val opt = scala.Some.apply[String]("foo");
[error]   val aString = "";
[error]   (if (Foo.this.logger.underlying.isErrorEnabled())
[error]     Foo.this.logger.underlying.error("{} {}", (scala.Array.apply[java.io.Serializable](opt, aString)((ClassTag.apply[java.io.Serializable](classOf[java.lang.Object]): scala.reflect.ClassTag[java.io.Serializable])): _*))
[error]   else
[error]     (): Unit)
[error] })
[error]   lift {
[error]        ^

orium avatar Jul 04 '18 15:07 orium

As I pointed out in scala/bug#11426, I recommend you reconsider how you're using resetAllAttrs. We could theoretically emit a fully-qualified reference to ClassTag, but you'd still be at the mercy of all other macro writers whose libraries your users wished also to use.

hrhino avatar Mar 10 '19 00:03 hrhino

Removing the call to resetAllAttrs makes the following example no longer compile:

object Demo {
  import scala.concurrent.ExecutionContext.Implicits.global
  import MonadlessFuture.{ lift, unlift }

  def demo: Future[Int] = {
    val future: Future[Int] = lift { 5 }
    lift {
      val n = unlift(future)
      n + 1
    }
  }
}
[info] Compiling 1 Scala source to /private/tmp/mrepro/monadless/monadless-stdlib/target/scala-2.11/classes...
[error]
[error]   symbol value n#30017 does not exist in io.monadless.stdlib.Demo.demo, which contains locals value future#29246.
[error] Method code: def demo(): scala.concurrent.Future[scala.Int] = {
[error]   val future: scala.concurrent.Future[scala.Int] = ((Future.apply({
[error]     ((new <$anon: Function0#2051>()): Function0#2051)
[error]   }, scala.concurrent.ExecutionContext$Implicits.global())): scala#21.concurrent#2752.Future#8567);
[error]   ((future.map({
[error]     ((new <$anon: Function1#1706>(n)): Function1#1706)
[error]   }, scala.concurrent.ExecutionContext$Implicits.global())): scala#21.concurrent#2752.Future#8567)
[error] }
[error]      while compiling: /private/tmp/mrepro/monadless/monadless-stdlib/src/main/scala/io/monadless/stdlib/MonadlessFuture.scala
[error]         during phase: icode
[error]      library version: version 2.11.8
[error]     compiler version: version 2.11.8
...
[error]   last tree to typer: Ident(n$1)
[error]        tree position: line 29 of /private/tmp/mrepro/monadless/monadless-stdlib/src/main/scala/io/monadless/stdlib/MonadlessFuture.scala
[error]             tree tpe: Int#1103
[error]               symbol: value n$1#39664
[error]    symbol definition: n$1#39664: Int#1103 (a TermSymbol)
[error]       symbol package: io.monadless.stdlib
[error]        symbol owners: value n$1#39664 -> constructor Demo$$anonfun$demo$1#32067 -> <$anon: Function1#1706>
[error]            call site: <$anon: Function1#1706> in package stdlib#8236 in package stdlib#8235
[error]
[error] == Source file context for tree position ==
[error]
[error]     26   def demo: Future[Int] = {
[error]     27     val future: Future[Int] = lift { 5 }
[error]     28     lift {
[error]     29       val n = unlift(future)
[error]     30       n + 1
[error]     31     }

dsilvasc avatar Mar 10 '19 00:03 dsilvasc