Ticket Created
over 3 years ago

CIQQA-1330

Parser bug with unused expression statements

The following code:

import Toybox.Lang;

function foo() as Boolean {
    return true;
}
function bar() as Void {
    (foo() || true);
}

reports

ERROR: <device>: Could not parse Monkey C IR.

It's caused by line 7.

If I change the program to:

import Toybox.Lang;

function foo() as Number {
    return 4;
}
function bar() as Void {
    (foo() + 1);
}

Then with type checking enabled I get:

ERROR: <device>:bug.mc:7: Cannot perform operation 'add' on types 'Null' and '$.Toybox.Lang.Number'.

So we're doing a bit better. It generated a valid .mir file, but note that foo() returns a Number, not Null, so the type checker seems like it's confused.

Looking at the .mir file though, I see:

    %tmp.1 = self;
    %tmp.2 = getv const %tmp.1 :foo;
    invoke %tmp.1 %tmp.2();
    %tmp.3 = 1;
    %tmp.4 = add null %tmp.3;

So it appears to completely ignore the result of the call, and then pulls an add of null and %tmp.3 out of the air. So the type checker's complaint is valid (based on the .mir that got generated). So it looks like incorrect mir files in both cases; but one parses and the other doesn't.