I'm trying to implement an implicit Not[T]
in Scala, and as such I want to throw an compiler error when there is an implicit val in scope of type T
. I thought of doing this using ambiguous implicits as the Scaladoc shows a way to implement =!=
. (See below)
But, I don't understand why two newAmbig
s are necessary, because there still seems to be an ambiguous implicit if I remove one, as there originally seems to be 3 viable implicits. (See below)
I could not find any documentation on what is required for the compiler to flag an ambiguous implicit.
The implementation of =!=
shown by the Scaladoc:
trait =!=[C, D]
implicit def neq[E, F] : E =!= F = null
@annotation.implicitAmbiguous("Could not prove ${J} =!= ${J}")
implicit def neqAmbig1[G, H, J] : J =!= J = null
implicit def neqAmbig2[I] : I =!= I = null
implicitly[Int =!= Int]
The implementation of =!=
that seems to work but does not:
trait =!=[C, D]
implicit def neq[E, F] : E =!= F = null
@annotation.implicitAmbiguous("Could not prove ${J} =!= ${J}")
implicit def neqAmbig1[G, H, J] : J =!= J = null
implicitly[Int =!= Int]
As both the neqAmbig1
and neq
should be of the same type, and both should be found.
But, this doesn't throw a compiler error, and when tested, just returns null
.