This page is no longer maintained — Please continue to the home page at www.scala-lang.org

trait vals initialization order

No replies
Marcelo Fukushima
Joined: 2009-01-09,
User offline. Last seen 42 years 45 weeks ago.

Hello again (it seens i always send emails to complain, but what can i do?)

I think ive found a bug, but since i couldnt find it in Trac, it might
just be intentional

consider a simple trait:

trait A {
val list: List[String] //any non "constant" value

val first = list.firstOption //any method will do
}

all implementations of this trait throws NullPointerException - at
least in 2.7.2-final and 2.7.3-RC2. Is this intended? If not, it
happens like this because the trait $init method is called before the
assignment for the generated list field

thanks for the attention

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland