I defined an extension method on a context function in Scala 3:
object Scope {
extension [E, A](a: List[E] ?=> A) def extFoo: A = foo(a)
private def foo[E, A](a: List[E] ?=> A) = {
given s: List[E] = List.empty
println(a)
a
}
}
However, when I try to use it, the compiler complains. The following @main
:
@main def main(): Unit = {
val i: List[String] ?=> Int = 1
import Scope.extFoo
i.extFoo
}
generates this error:
No given instance of type List[String] was found for parameter of (List[String]) ?=> Int
i.extFoo
Everything works fine if I call the extension method with the alternative syntax, extFoo(i)
.
Is it the expected behavior?