Skip to content

Type flow analysis issues with nullable class variables #66

@m4tiz5zktonj

Description

@m4tiz5zktonj
import Toybox.Lang;

//

class C1 {
    function f1() as Void {}
}

class C2 extends C1 {
    private var x as Number?;
    private var y as Number?;

    function initialize() {
        C1.initialize();
    }

    function f2() as Number {
        if (x != null && y != null) {
            f1();

            return x + y; // Unexpected types for operator '+': [Number vs Null], [Null vs Null or Number]
        } else {
            return 0;
        }
    }
}

//

class C3 {
    private var z as Array<Number>?;

    function f3() as Array<Number> {
        if (z != null) {
            (z as Array<Number>)[0] = 0;

            return z; // Expected $.C3.f3 to return Array<Number> but got Null or Array<Number>
        } else {
            return [] as Array<Number>;
        }
    }
}

Plugin version is 2.0.121. Builds without errors with SDK 8.4.0 and strict type checking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions