I used the Scala 2.0 interpreter...
class Up {}
class Middle extends Up {}
class Bottom extends Middle {}
class Top { def cv(t: Up) = "Top"; def inv(m: Middle) = "Top"; def ctv(b: Bottom) = "Top"; }
class Down extends Top {def cv(m: Middle) = "Down";override def inv(m: Middle) = "Down"; def ctv(m: Middle) = "Down";}
def testcv1(t: Top) = {Console.println(t.cv(new Up()));Console.println(t.cv(new Middle()));Console.println(t.cv(new Bottom()));}
def testcv2(d: Down) = {Console.println(d.cv(new Up())); Console.println(d.cv(new Middle())); Console.println(d.cv(new Bottom()));}
def testinv1(t: Top) = {Console.println("type mismatch; found : Up required: Middle");Console.println(t.inv(new Middle()));Console.println(t.inv(new Bottom()));}
def testinv2(d: Down) = {Console.println("type mismatch; found : Up required: Middle");Console.println(d.inv(new Middle()));Console.println(d.inv(new Bottom()));}
def testctv1(t: Top) = {Console.println("type mismatch; found : Up required: Bottom");Console.println("type mismatch; found : Middle required: Bottom") ;Console.println(t.ctv(new Bottom()));}
def testctv2(d: Down) = {Console.println("type mismatch; found : Up required: Bottom");Console.println(d.ctv(new Middle()));Console.println("ambiguous reference to overloaded definition, both method ctv in class Down of type (line2$object.Middle)java.lang.String and method ctv in class Top of type (line3$object.Bottom)java.lang.String match argument types (line3$object.Bottom) and expected result type scala.Any"); }
-- run
scala> Console.println("First column");
testcv1(new Top());
testinv1(new Top());
testctv1(new Top());
Console.println("Second column");
testcv2(new Down());
testinv2(new Down());
testctv2(new Down());
Console.println("Third column");
testcv1(new Down());
testinv1(new Down());
First column
line15: scala.Unit = ()
scala> Top
Top
Top
line16: scala.Unit = ()
scala> type mismatch; found : Up required: Middle
Top
Top
line17: scala.Unit = ()
scala> type mismatch; found : Up required: Bottom
type mismatch; found : Middle required: Bottom
Top
line18: scala.Unit = ()
scala> Second column
line19: scala.Unit = ()
scala> Top
Down
Down
line20: scala.Unit = ()
scala> type mismatch; found : Up required: Middle
Down
Down
line21: scala.Unit = ()
scala> type mismatch; found : Up required: Bottom
Down
ambiguous reference to overloaded definition, both method ctv in class Down of t
ype (line2$object.Middle)java.lang.String and method ctv in class Top of type (
line3$object.Bottom)java.lang.String match argument types (line3$object.Bottom)
and expected result type scala.Any
line22: scala.Unit = ()
scala> Third column
line23: scala.Unit = ()
scala> Top
Top
Top
line24: scala.Unit = ()
scala> type mismatch; found : Up required: Middle
Down
Down
line25: scala.Unit = ()
scala> testctv1(new Down());
type mismatch; found : Up required: Bottom
type mismatch; found : Middle required: Bottom
Top
line26: scala.Unit = ()
scala>