Acknowledged

sdk-6.2.2 changes lookup rules for class statics

This code:

module MyMod {
    const ModConst = 2;
    class Base {
        static const BaseConst = 3;
    }
}

class Test extends MyMod.Base {
    function initialize() {
        Base.initialize();
    }
    static const TestOne = ENDIAN_BIG;
    static const TestTwo = ModConst;
    static const TestThree = BaseConst;
}

function test() {
  System.println(Test.TestOne);
  System.println(Test.TestTwo);
  System.println(Test.TestThree);
}

Compiles (even with Strict type checking) and runs as you might expect prior to sdk-6.2.2. ie

  • TestOne is assigned the value of Lang.ENDIAN_BIG (it finds it by following the inheritance chain to MyMod.Base, then Lang.Object, and then searches out from Lang.Object to find Lang.ENDIAN_BIG).
  • TestTwo is assigned the value of MyMod.ModConst (again, it follows the inheritance chain to MyMod.Base, and then searches out to MyMod)
  • TestThree is assigned the value of Base.BaseConst.

With the default optimization level, you can see (via -g) that the values have been substituted at compile time, so no runtime lookups actually happen. But if you set optimization level to 0, no substitutions happen, and it's clear that all the lookups happen at runtime, and work.

With sdk-6.2.2 the type checker complains that ENDIAN_BIG, ModConst and BaseConst don't exist, and refuses to compile. If you turn the type checker off, it then compiles, but crashes at runtime because the symbols don't exist (and I've verified by testing each of the three cases separately that all of them fail).

So the runtime has been changed, and the type checker has been updated to match - making me think this is an intentional change. But it breaks existing code, and its not clear what it might fix...

Also note that similar code without "static" continues to work.

Parents
  • What's static vs non static is supposed to mean for const?

    I think in Monkey C, non-static class variables are only supposed to be accessible through an instance, while static class variables are only supposed to be accessible through the class itself, regardless of whether the const qualifier is present or not.

    (Yes, I realize that a non-static const variable would be no improvement over a static const variable.)

Comment
  • What's static vs non static is supposed to mean for const?

    I think in Monkey C, non-static class variables are only supposed to be accessible through an instance, while static class variables are only supposed to be accessible through the class itself, regardless of whether the const qualifier is present or not.

    (Yes, I realize that a non-static const variable would be no improvement over a static const variable.)

Children
No Data