[#500] | project: nsc | priority: low | category: bug | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Philippe | Martin | fixed | 2005-11-28 13:39:37.0 | |
subject | Scala is unsound | |||
code |
object Magic { abstract class O[X,Y] { type T >: X <: Y; class I { def magic(v: T): T = v; } } def magic[X,Y](v: X): Y = { val o: O[X,Y] = null; val i: o.I = new o.I(); i.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 expression new o.I() raises no NPE although o is null .
|
|||
[back to overview] |
Philippe edited on 2005-11-28 14:21:21.0 |
Changed project to "nsc". |
Martin edited on 2006-02-02 14:36:08.0 |
Martin edited on 2006-02-02 14:36:38.0 |