Question

Why does this code crash the Scala 2.8.1 compiler?

val a = new Array[{ var x = 1 }](3)

Is it a compiler bug?

Anyway is it a legal Scala code? (I want an array of objects with anonymous class type)

Update:

What I want is something like:

class X { var x = 1}
val a = new Array[X](3)

but without having to define standalone X

Was it helpful?

Solution

Compiler crashes are always bugs. But why are you trying to set x equal to 1 in the type declaration?

Your probably want one of these:

val a = new Array[{var x: Int}](3)
val a = Array.fill(3)(new { var x = 1 })

(and the compiler is happy with either of these).

OTHER TIPS

It doesn't crash for me (Scala 2.8), so it is likely a bug.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top