1
votes

The following:

object SomeObj {
  def addVertex(cc: Product): String = ???
  def addVertex(cc: AnyRef): String = ???
}

case class Toto(s: String)

SomeObj.addVertex(Toto(""))

Is doing:

Error:(8, 10) ambiguous reference to overloaded definition,
both method addVertex in object SomeObj of type (cc: Object)String
and  method addVertex in object SomeObj of type (cc: Product)String
match argument types (A$A34.this.Toto)
SomeObj.addVertex(Toto(""));}
        ^

Why? Shouldn't it go for the most specific one?
Interestingly with Any instead of AnyRef it works.

Cheers

1
Not really, your example works for me without the mentioned error. What version of Scala are you using?Mifeet

1 Answers

0
votes
trait Product extends Any with Equals 
trait Equals extends Any

Here you can see that Product does not extend AnyRef and not derived from it, so it is not more specific than AnyRef and compiler can't choose among them. But Product is a subclass of Any, therefore it is more specific than Any, that's why your another variant compiles succesfully.