Complete
over 2 years ago

This is a known issue currently and still being investigated.

Type checker fails to remove Null in some cases

import Toybox.Lang;

function a() as Number or Null {
    return 42;
}

function b() as Float or Null {
    return 24.0;
}

function odd(x as Boolean) as Numeric? {
    var v = x ? a() : b();
    if (v != null) {
        return v * 24;
    }
    return null;
}

ERROR: <device>: bug.mc:14: Attempting to perform operation 'mul' with invalid types 'Null' and '$.Toybox.Lang.Number'.

At the point of definition, v should be typed as Number or Float or Null - and regardless, it can't possibly be Null on line 14.

The error goes away if a() and b() both return the same type - even if the type is Number or Float or Null.