trait Foo
trait Bar extends Foo
def doStuff[T <: Foo](x: T)(implicit ev: T =!:= Foo) = x
doStuff(new Foo{}) //ambiguous implicit value
doStuff(new Bar)// successful
Implicit resolution occurs at compile time, so here I think there may be two implicit values with exactly the same type to cause ambiguous material.
Right now, I'm going to introduce the formless into the team, my colleagues believe that this ambiguous implicit is not perfect, and I have no good reason. This is the only way to do this to make the type safe in scala. If so, what can I do to customize the error message?
Edit:
In formless, I want to make the sum of 2 NATs not equal to 7, I can make the code in such a way as to compile the compilation.
def typeSafeSum[T <: Nat, W <: Nat, R <: Nat](x: T, y: W)
(implicit sum: Sum.Aux[T, W, R], error: R =:!= _7) = x
typeSafeSum(_3, _4)
, ?