Closed da-steve101 closed 8 years ago
This is an underlying issue with how Scala works. (I suppose the argument can be made that Chisel entices you to put so much in the Module constructor, which is somewhat non-ideal as it manifests this issue.)
All of the vals (and defs and vars*) become fields of the ultimate underlying Scala/Java object. Hence how you can reference them later with the dot operator. When the constructor is executed, the vals and vars are initialized 'in-order' of their declaration in the constructor (also in-between any statements that need to be executed. Note that you can access defs or lazy vals 'out-of-order' (although flaws in the current Chisel implementation make using lazy val very dangerous) since they really define functions that don't require initialization.
The scala compiler tries to catch some of these errors (hence seeing the out2 issue) but apparently misses some. You may want to raise this case with the scalac developers. They are in the process of unveiling a redone compiler toolchain so it may be a good time to ask to improve the invalid reference detection.
(* You should generally avoid using vars)
Had a cryptic error message that was difficult to debug. Came down to a null pointer from things defined out of order but wasn't detected. It seems to be when assigning to the Vec (perhaps Bundle in general but i haven't tested)
Here is the error message
For out2 in the example code above you get the nice warning such as: