Acknowledged

SDK 8.0.0 beta: issue with conditionals from 7.4.1 is still present

There's a problem in early SDK 7.4.* versions (that have been pulled back) and in SDK 8.0.0 beta with enabled strict type checking:

import Toybox.Lang;

function f(x as Number) as Number? {
    // Object of type 'PolyType<Any or $.Toybox.Lang.Number>' does not match return type 'PolyType<Null or $.Toybox.Lang.Number>'.
    return x != null ? x : null;
}

Such code builds without errors in 7.3.1 and 7.4.3.

Parents
  • This (not exactly, but logically very similar) code is produced by PMC, but I think, this is not a PMC's problem.

    I have a function in barrel, that takes nullable argument and two apps, that use this barrel, and one app can pass null, while another one can't. PMC optimizes code of the second app in the way, that it passes non-nullable variable "x" in "x != null ? y(x) : null" expression. Yes, ideally we would expect PMC to optimize code even more to return "y(x)" directly, but I'm OK with current optimizations for now.

    In other words: yes, this code looks bad, but it was generated, and I think it should build and work as it syntactically correct.

Comment
  • This (not exactly, but logically very similar) code is produced by PMC, but I think, this is not a PMC's problem.

    I have a function in barrel, that takes nullable argument and two apps, that use this barrel, and one app can pass null, while another one can't. PMC optimizes code of the second app in the way, that it passes non-nullable variable "x" in "x != null ? y(x) : null" expression. Yes, ideally we would expect PMC to optimize code even more to return "y(x)" directly, but I'm OK with current optimizations for now.

    In other words: yes, this code looks bad, but it was generated, and I think it should build and work as it syntactically correct.

Children
No Data