Closed
Description
Currently we are unable to override a method with an implicit method as the implicit method is not a subtype of the plain method. This is in used in the definitions of the synthetic symbols for ImplicitFunctionN
but it does not work properly. I found the following two issues
- Dotty complains when we try to override a method with its equivalent implicit method.
- We are forced to implement
ImplicitFunctionN.apply
without theimplicit
. Making the function class implementingImplicitFunctionN
behave as aFunctionN
.
object Test {
def main(args: Array[String]): Unit = {
implicit val x: String = "hello"
val i0: Int = new Fun0().apply
val i1: Int = new Fun1().apply
// ^^^^^^^^^^^^
// missing arguments for method apply in class Fun1
// follow this method with `_' if you want to treat it as a partially applied function
val i2: Int = new Fun2().apply // works as expected
}
}
class Fun0 extends ImplicitFunction1[String, Int] {
def apply(implicit x: String): Int = 42
// overriding method apply in trait Function1 of type (v1: String)Int;
// method apply of type (implicit x: String)Int has incompatible type
}
class Fun1 extends ImplicitFunction1[String, Int] {
def apply(x: String): Int = 43
}
class Fun2 {
def apply(implicit x: String): Int = 44
}
class A {
def foo(x: String): Unit = ()
}
class B extends A {
def foo(implicit x: String): Unit = ()
// overriding method foo in trait A of type (x: String)Unit;
// method foo of type (implicit x: String)Unit has incompatible type
}