How to call an overload which only distinguishes itself via upper bound

Consider the following:

trait A
trait SubA extends A
class AImpl extends A
class SubAImpl extends SubA

trait B[-E <: A] {
  def foo[SubE <: E](e: SubE): SubE
}  

abstract class Base extends B[A] {
  def foo[SubE <: A](e: SubE): SubE = 
    println("in Base")
    e
}

trait SubB extends B[SubA]

class D extends Base with SubB {
    def foo[SubE <: SubA](e: SubE): SubE = 
      println("in D")
      // how to call Base.foo here?
      // edit found the solution:
      (this: Base).foo(e) 
}



D().foo(SubAImpl()) 
D().foo(AImpl())

Welcome to the Scala community, @robstoll :wave:

I was able to make it type-check (after fixing syntax errors, and making the type parameter contravariant): Scastie - An interactive playground for Scala. But I have no idea what the intention is here.

Thanks for the fixes, I have updated the example. However, using foo(e) will call itself and not the method from Base.
`

1 Like

@spamegg1 thanks, took a look over my actual problem and was actually able to fix it without the need to call an overload which only differs in upper bound. I forgot the extends B in Base extends B that was the reason that I had to implement twice method foo.

I now also found out how to call the method from Base

(this: Base).foo(e) 
1 Like