What is syntactical difference between `given` and `implicit val`?

I have an Akka actor:

object AnActor: 
  private def handle(): Behavior[Command] =
    Behaviors.receive { (context, msg) =>
      msg match
        case ACommand() =>
          implicit val logger: Logger = context.log // works
          given logger: Logger = context.log // fails at runtime: java.lang.UnsupportedOperationException: Unsupported access to ActorContext operation from the outside of Actor
          val aRoutine: Future = // ...
          aRoutine.onComplete(x => logger.info(x))
    }

For some reason logger defined by given escapes a thread. Why?

And how to define a given properly?

BTW what is a tool to check Java-ish code generated by Scala compiler?

https://docs.scala-lang.org/scala3/reference/contextual/givens.html#given-instance-initialization-1

It’s lazy. I guess that is a semantic difference. Or is it a tactical difference?

1 Like

CFR

If you use Metals, you even have an option to decompile your code with CFR.

2 Likes