-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perform 'late' value initialization non-polymorphically, *sometimes* #11
Comments
Of course, when they are initialized polymorphically, there is no way to initialize the refined value. So, within |
Actually, the results on the JVM are inconsistent too, when the class AA() {
shared default late Object i;
shared default late Object j;
shared void initialize(Object x) {
this.i = x;
this.j = x;
}
}
class BB() extends AA() {
shared actual variable Object i = "1";
shared actual variable String j = "1";
}
shared void runX() {
value b1 = BB();
b1.initialize(2);
printAll { b1.i, b1.j };
// 2, 1 on JVM
// 1, 1 on JS
// 2, 2 on Dart
} And initializing refined class AAA() {
shared default late Object i;
shared default void initialize(Object x) {
this.i = x;
}
}
class BBB() extends AAA() {
shared actual late Object i;
shared actual void initialize(Object x) {
super.initialize(1);
this.i = x;
// JVM ERROR: ceylon.language.InitializationError "Re-initialization of 'late' attribute"
}
shared Object superI => super.i;
}
shared void run() {
value b1 = BBB();
b1.initialize(2);
print(b1.i); // 2
print(b1.superI);
// JVM: ERROR: ceylon.language.InitializationError "Accessing uninitialized 'late' attribute 'i'"
// JS: 1
} |
A couple options: Option A
Option B Same as A), but allow I'm currently leaning towards B), which pretty much matches the current JS behavior. |
To be clear, we know that shared default Integer x = 0; "non-polymorphically" initializes It seems natural that the following would be exactly the same: shared default late Integer x;
x = 0; But, when shared default late variable Integer x;
x = 0;
|
The most reasonable (edit: or not... see below) output for the code below is what the JVM produces, where the assignment to a
late
value is non-polymorphic unless the value has alate
orvariable
refinement.I'm guessing the JVM behavior is a natural result of
setX()
refinements existing forj
andk
, but noti
.OTOH, @gavinking, should each of these be allowed?
The text was updated successfully, but these errors were encountered: