Acknowledged
CIQQA-3582

Failure of derived class to call super.initialize() should be an error and not a warning, because this can break the type checker's "guarantees" and lead to run-time type errors

The fact that it's only a warning leads to potential situations which break the type checker's guarantee that a member variable has a certain non-null type, leading to potential run-time errors.

class Example {
    var thing as Float;
    function initialize() {
        thing = 1.0;
        /// Yay, thing is def initialized
    }
}

class Bar extends Example {
    function initialize() { // WARNING: Class 'Bar' does not initialize its super class 'Example'.
        // it's too bad this is only a warning
    }

    function bar() as Void {
        System.println("thing = " + thing);
    }
 }

 function test() as Void {
    var b = new Bar();
    b.bar(); // prints "thing = null"
    // Bar.thing actually has a default value of null, even though the type checker guarantees it's a Float :/

    var y = b.thing / 2.0; // run-time crash due to unhandled exception 😔
        // Exception: UnexpectedTypeException: Expected Number/Float/Long/Double, given null/Float
    System.println("b.thing / 2.0 = " + y);
 }

  • I understand why you say what you say. Of course in theory the type checker could also be fixed for these cases.

    My only problem with changing the warning to error is that in my datafields that are very close to the memory limit one trick I used is not to call the super.initialize() to save a few bytes of code.

    So instead I'd say: let's make the compiler clever enough: throw an error only if there is a non-empty constructor in (any of) the ascendant classes and remove the warning when they don't do anything.

  • Even before Monkey Types, I never understood why derived classes were allowed to skip calling super.initialize(). In my mind, either:

    - super.initialize() should be called implicitly / automatically (in the absence of an explicit call)

    or

    - it should be an error if a derived class fails to call super.initialize()

    If class B extends class A, but B does not call A.initialize(), in what sense is an instance of B truly also an instance of A? (Ofc this question is especially relevant if the Monkey Types system is considered.)