Aladdin - Scala Bugtracking
[#501] project: nsc priority: low category: bug
submitter assigned to status date submitted
Philippe Martin fixed 2005-11-28 13:39:45.0
subject Scala is unsound
code
object Magic {
  class O[X,Y] {
    abstract class I { type T >: X <: Y; }
    val i: I = null;
    def magic(v: i.T): i.T = v;
  }
  def magic[X,Y](v: X): Y = {
    val o: O[X,Y] = new O();
    o.magic(v);
  }
}

object Test {
  def main(args: Array[String]): Unit = {
    val i: Int = Magic.magic("42");
    System.out.println(i);
  }
}
what happened
Exception in thread "main" java.lang.ClassCastException
	at Test$.main(test.scala:16)
	at Test.main(test.scala)
what expected The method Magic.magic converts any value of any type X to any other type Y without using any cast. The implementation relies on the fact that the method Magic.O.magic raises no NPE although its argument type and return type extract the type T from the value i which is null.
[back to overview]
Changes of this bug report
Philippe  edited on  2005-11-28 14:21:09.0
Changed project to "nsc".
Martin  edited on  2006-02-02 15:28:08.0
I am not claiming (yet) that scala is sound but the particular two problems that Philippe has discovered are fixed. Bug 501 is fixed because lower bounds must now statically conform to upper bounds. Bug 500 is fixed because outer references are now checked to be non-null.