Consider the following hierarchy:
class C1
class C2 extends C1
class C3 extends C2
class C4 extends C3
I want to write a function that just accepts C2and types C3. For this, I thought of the following:
def f [C >: C3 <: C2](c :C) = 0
I expect the following behavior
f(new C1)
f(new C2)
f(new C3)
f(new C4)
The problem is calling with C4, which I do not want to resolve, but the compiler accepts. I understand what C4 <: C2is right and what C4can be considered as C3. But when specifying a border, [C >: C3 <: C2]I would expect the compiler to find Cone that will evaluate both borders at the same time, and not one by one.
Question: is there a way to achieve what I want, and if not, does the compiler try to avoid some inconsistency with this?
: , . C4 C >: C3, . - C3 <:< C.