This is a followup to my Debugging transparent inline functions question as it turns out my problem has more to do with overloading than transparent inline.
This code works, and I don’t understand why:
def wf[A](code: ExecutionContext => A): Unit =
code(ExecutionContext.global)
def wf[A](code: ExecutionContext => Future[A]): A =
Await.result(code(ExecutionContext.global), Duration.Inf)
wf(e => Future("X")(using e))
wf(_ => "Y")
Don’t both wf functions have the same signature, Function1, after type erasure?
Then, this doesn’t work:
def wc[A](code: ExecutionContext ?=> A): Unit =
code(using ExecutionContext.global)
def wc[A](code: ExecutionContext ?=> Future[A]): A =
Await.result(code(using ExecutionContext.global), Duration.Inf)
wc(Future("X"))
wc("Y")
The wc functions have the same bytecode-level signatures as the wf functions and can be compiled. However, neither can be invoked:
None of the overloaded alternatives of method wc with types
[A](code: (scala.concurrent.ExecutionContext) ?=> scala.concurrent.Future[A]): A
[A](code: (scala.concurrent.ExecutionContext) ?=> A²): Unit
match arguments (scala.concurrent.ExecutionContext => scala.concurrent.Future[String])
Found: ("Y" : String)
Required: scala.concurrent.ExecutionContext => <?>
I understand that overloading is messy (I’m trying to quit…), but I’d still like to understand what’s going on here.