Open soronpo opened 4 years ago
-Vimplicits
says:
t11929.scala:15: TwoFaceInt.<apply: error> is not a valid implicit value for 2 => TwoFaceInt[?T] because:
ambiguous reference to overloaded definition,
both method apply in object TwoFaceInt of type [T <: Int with Singleton](value: T)TwoFaceInt[T]
and method apply in object TwoFaceInt of type [T <: Int with Singleton](implicit value: T)TwoFaceInt[T]
match argument types (Int) and expected result type TwoFaceInt[?T]
val b : Fooish[2] = a.foo(2.asInstanceOf[2])
^
t11929.scala:15: TwoFaceInt.<apply: error> is not a valid implicit value for (=> 2) => TwoFaceInt[?T] because:
ambiguous reference to overloaded definition,
both method apply in object TwoFaceInt of type [T <: Int with Singleton](value: T)TwoFaceInt[T]
and method apply in object TwoFaceInt of type [T <: Int with Singleton](implicit value: T)TwoFaceInt[T]
match argument types (Int) and expected result type TwoFaceInt[?T]
val b : Fooish[2] = a.foo(2.asInstanceOf[2])
^
t11929.scala:15: error: overloaded method value foo with alternatives:
[T](value: TwoFaceInt[T])Fooish[value.Out] <and>
=> Fooish[4]
cannot be applied to (Int)
val b : Fooish[2] = a.foo(2.asInstanceOf[2])
^
one error found
It will plow through that:
trait Helper
object Helper {
implicit def helper[T <: Int with Singleton with Helper](value : T) : TwoFaceInt[T] = ???
}
object Test extends App {
val a = new Foo
val b : Fooish[2 with Helper] = a.foo(2.asInstanceOf[2 with Helper])
}
then
t11929.scala:6: error: double definition:
def apply[T <: Int with Singleton](implicit value: T): TwoFaceInt[T] at line 5 and
implicit def apply[T <: Int with Singleton](value: T): TwoFaceInt[T] at line 6
have same type after erasure: (value: Int)TwoFaceInt
implicit def apply[T <: Int with Singleton](value : T) : TwoFaceInt[T] = ???
^
one error found
reproduction steps
Use the following code:
problem
The error generated is very misleading:
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: