Open
Description
reproduction steps
Use the following code:
trait TwoFaceInt[T] {
type Out = T
}
object TwoFaceInt {
def apply[T <: Int with Singleton](implicit value : T) : TwoFaceInt[T] = ???
implicit def apply[T <: Int with Singleton](value : T) : TwoFaceInt[T] = ???
}
trait Fooish[T]
class Foo {
final def foo : Fooish[4] = ???
final def foo[T](value : TwoFaceInt[T]) : Fooish[value.Out] = ???
}
val a = new Foo
val b : Fooish[2] = a.foo(2)
problem
The error generated is very misleading:
Error: overloaded method value fooy with alternatives:
[T](value: TwoFaceInt[T])Fooish[value.Out] <and>
=> Fooish[2]
cannot be applied to (Int)
val b : Fooish[2] = a.fooy(2)
It should be noted that if we remove final def foo : Fooish[4] = ???
, no error would have been generated.
expectation
The actual source of the problem is that inside TwoFaceInt
the two methods have the same signature.
In dotty we get an error as expected:
Double definition:
def apply: [T <: Int & Singleton](implicit value: T): TwoFaceInt[T] in object TwoFaceInt at line 10 and
implicit def apply: [T <: Int & Singleton](value: T): TwoFaceInt[T] in object TwoFaceInt at line 11
have the same type after erasure.