I have an abstract class with an unimplemented method numbers that returns a list of numbers, and this method is used in another val property initialization:
Here is what your code attempts to do when it initializes MainFoo:
val calcNumbers and val numbers, initially set to 0.Foo, where it attempts to invoke numbers.map while initializing calcNumbers.MainFoo, where it initializes numbers to List(1, 2, 3).Since numbers is not initialized yet when you try to access it in val calcNumbers = ..., you get a NullPointerException.
Possible workarounds:
numbers in MainFoo a defnumbers in MainFoo a lazy valcalcNumbers in Foo a defcalcNumbers in Foo a lazy valEvery workaround prevents that an eager value initialization invokes numbers.map on a non-initialized value numbers.
The FAQ offers a few other solutions, and it also mentions the (costly) compiler flag -Xcheckinit.
You might also find these related answers useful:
Scala overridden value: parent code is run but value is not assigned at parent.
Assertion with require in abstract superclass creates NPE