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 is happening on compilation time, so in here I think there may be two implicit value with exactly same type to trigger ambiguous stuff.
Right now, I am going to introduce shapeless into the team, my colleagues think this ambiguous implicit is not ideal, and I dont have strong argument about it. Is this only way to do it in order to make type safe in scala. If it is, what can I do to customize the error message ?
Edit:
In the shapeless, I want to make the sum of 2 NAT not equal to 7, I can code like this to make compilation fail.
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)
but the error message is ambiguous implicit value, how can I customize the error message ?