Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "ambiguous reference to overloaded definition" for methods with different signatures?

I know there are a number of other questions about this error, but the others are pretty clear why there's an error. In my case, I can't understand why. Here's a short example:

trait A {
  def text: String = "abc"
}
case object B extends A {
  def text(s: Seq[String]): String = s.mkString
}

Now, calling B.text I would expect to be unambiguously resolved to the method inherited from the base trait since the one in object B doesn't even match the calling signature... but yet, error!

<console>:13: error: ambiguous reference to overloaded definition, both method text in object B of type (s: Seq[String])String and method text in trait A of type => String match expected type ? B.text ^

Is this "normal"/expected?

like image 500
borice Avatar asked Nov 29 '25 13:11

borice


1 Answers

B.text can be considered on the one hand as calling text method from trait A and on the other hand as eta-expanded method from B that will return the function of type Seq[String] => String

like image 67
simpadjo Avatar answered Dec 02 '25 05:12

simpadjo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!