Skip to content

initialization order problems merging header defaults with native implementations #1447

@jvasileff

Description

@jvasileff

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions