shared void run() {
print(X.x.y.x); // JVM: <null>
}
class X {
shared Y y;
shared new x {
y = Y.y;
}
}
class Y {
shared X x;
shared new y {
x = X.x;
}
}
4474 addressed a specific, detectable case of cyclic initialization of value constructors, but for the example above, it seems a runtime check will be necessary.
I suggest that the rules in 8.2.10. Initialization of toplevel references be generalized to cover value constructors, particular with respect to throwing an InitializationError when cycles occur.
The following prints
<null>
on the JVM:4474 addressed a specific, detectable case of cyclic initialization of value constructors, but for the example above, it seems a runtime check will be necessary.
I suggest that the rules in 8.2.10. Initialization of toplevel references be generalized to cover value constructors, particular with respect to throwing an
InitializationError
when cycles occur.Note that I'm advocating for the same for
static
s in https://github.com/ceylon/ceylon/issues/6821#issuecomment-266244728 and https://github.com/ceylon/ceylon/issues/6720.