Allow `apply` method calls instead of false `using` blocks

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.

Not sure what you mean, that code works as expected.

This was a problem in Scala 2 with implicits, but one of the goals of the new given / using syntax was that you must be double explicit when passing an implicit parameter explicitly.

1 Like

You are right!!!
I was sure it didn’t because of the Scala 2.
Nice! Another point for Scala 3!

1 Like