nowarp / misti

TON Static Analyzer
https://nowarp.io/tools/misti
Apache License 2.0
29 stars 1 forks source link

Detect `while`/`until`/`repeat` loops that could be replaced with `foreach` #42

Open byakuren-hijiri opened 3 months ago

byakuren-hijiri commented 3 months ago

It is possible to find while/until/repeat loops that could be safely replaced to foreach.

If the loop condition variable is increasing and only using to access a map element, we should suggest replacing the entire loop with foreach:

let m: map<Int, Int>;
let mSize: Int;

fun test() {
    let i: Int = 0;
    while (i < self.mSize) {
        i = i + 1;
        dump(self.m.get(i));
    }
}

Could be replaced with:

let m: map<Int, Int>;
let mSize: Int;

fun test() {
    let i: Int = 0;
    foreach (_k, v in self.m) {
        dump(v);
    }
}

Things to consider:

jubnzv commented 2 months ago

Depends on #70