Skip to content
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

initialization order problems merging header defaults with native implementations #1447

Open
jvasileff opened this issue Oct 23, 2015 · 1 comment

Comments

@jvasileff
Copy link
Member

As observed in ceylon/ceylon-compiler#2371, forward-reference checks can be circumvented. Issues with statement ordering with respect to declarations may exist as well.

This example produces surprising results where an immutable value seemingly changes, due to first being used in an uninitialized state:

shared native class C() {
    shared native Integer a = 1;
    shared native Integer b = 2;

    shared void printA() => print("a=``a``");
    shared void printB() => print("b=``b``");
}

shared native("jvm") class C() {
    shared native("jvm") Integer a = -b;
    printB();
}

shared void run() {
    value c = C(); // b=0
    c.printB();    // b=2
    c.printA();    // a=0
}

Similarly, a NullPointerException can occur:

shared native class C() {
    shared native Integer a = -1;
    shared native String b = "b";
}

shared native("jvm") class C() {
    shared native("jvm") Integer a = b.size;
    //java.lang.NullPointerException
    //  at ceylon.language.String.getSize(String.java:242)
}

ps - I realize this is not for 1.2.

@quintesse quintesse added this to the 1.3 milestone Oct 23, 2015
@quintesse
Copy link
Member

Thanks for opening an issue for this one so we won't forget it @jvasileff .

More discussion is still available in the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants