- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Change in construction order
Thu, 2009-01-22, 01:14
The following code succeeds with existing Scala releases, but gives a
NullPointerException with recent nightly builds for 2.8.0
trait A {
def f: String
}
abstract class B extends A {
val v = f.length
}
object C extends B with Application {
// def f = "" // succeeds
// lazy val f = "" // succeeds
val f = "" // NullPointerException in B.
}
In C's constructor, the putfield for f is now being performed after
calling the superclass constructor, instead of before. (Bytecode attached)
Is this intended?
On Thu, Jan 22, 2009 at 11:02:32AM +1100, Eric Willigers wrote:
> The following code succeeds with existing Scala releases, but gives a
> NullPointerException with recent nightly builds for 2.8.0
And you can actually get a much more explanatory message than is usually available, the catch
being that you have to know to compile with -Xexperimental.
$ scalac27 -Xexperimental a.scala
a.scala:12: warning: the semantics of this definition has changed;
the initialization is no longer be executed before the superclass is called
val f = "" // NullPointerException in B.
^
one warning found