Consider the following example
class Foo() {
def exec(using Context) : Array[Int] = ???
}
extension (foo : Foo)(using Context) {
def extExec : Array[Int] = ???
}
val foo = Foo()
foo.exec(1) //Error!
foo.extExec(1) //OK!
The error in foo.exec(1)
is because of the implicit (given) context argument, but we can avoid this by placing the context in an extension clause, as in extExec
.
Since in Scala 3 we cannot place a using
argument without explicit using
keyword (e.g., exec(using someContext)
, I propose that in this case, the compiler will check if it is possible to apply an apply
definition argument.