eclipse / mita

mita
Eclipse Public License 2.0
56 stars 20 forks source link

Side effects in array indices are run twice #233

Closed wegendt-bosch closed 6 years ago

wegendt-bosch commented 6 years ago
package main;
import platforms.xdk110;

let a = [1,2,3,4];
var b = 0;

every 100 milliseconds {
    let x = a[b++];
}

produces

Retcode_T HandleEvery100Millisecond1(void* userParameter1, uint32_t userParameter2)
{

    BCDS_UNUSED(userParameter1);
    BCDS_UNUSED(userParameter2);

    Retcode_T exception = NO_EXCEPTION;

    if(a.length <= b++) {
        exception = EXCEPTION_INVALIDRANGEEXCEPTION;
        if(exception != NO_EXCEPTION) return EXCEPTION_INVALIDRANGEEXCEPTION;
    }

    int32_t x = a.data[b++];

    return NO_EXCEPTION;
}

which increments b twice.