[#412] | project: compiler | priority: medium | category: bug | |
---|---|---|---|---|
submitter | assigned to | status | date submitted | |
Philippe | Martin | fixed | 2005-04-01 17:13:52.0 | |
subject | Compound Types and null values make Scala unsafe | |||
code |
object Magic { abstract class A[T1,T2]() { trait C { type T; } trait C1 extends C { type T = T1; } trait C2 extends C { type T <: T2; } type CX; val c: CX with C2 = null; def castA(x: c.T): T2 = x; } class B[T1,T2] extends A[T1,T2]() { type CX = C1; def castB(x: T1): T2 = castA(x); } def cast[T1,T2](v: T1): T2 = new B[T1,T2]().castB(v) } object Test { def main(args: Array[String]): Unit = { Magic.cast[String,Exception]("xyz").printStackTrace(); } } |
|||
what happened | The program compiles. At runtime, it raises the following error:Exception in thread "main" java.lang.ClassCastException at Test$.main(test.scala:28) at Test.main(test.scala:27) |
|||
what expected | The method The cast from To sum up, everything relies on the fact that in class
Without using def f: CX with C2 = f; val c: CX with C2 = f;but this prevents the creation of instances of B as their
initialization would never terminate.
|
|||
[back to overview] |
Martin edited on 2006-10-26 16:54:07.0 |
You now get:
bug412.scala:9 error: type mismatch; found : scala.Null(null) required: A.this.CX with A.this.C2 val c: CX with C2 = null; ^ one error foundGenerally, intersections with abstract types are no longer compatible with Null. |