HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.03k stars 648 forks source link

Inline function with continue inside loop no longer works #11606

Closed yuxiaomao closed 3 months ago

yuxiaomao commented 3 months ago

Recently the following code does not work anymore, with error "Continue outside loop". First bad commit https://github.com/HaxeFoundation/haxe/commit/2b0e8cead3374f0cab8d52ec0ec9b05e269a6750 and related PR https://github.com/HaxeFoundation/haxe/pull/11534, by reading the PR I don't think this is intended.

static public function main() {
    for (i in 0...5) {
        inline function dothings(v:Int) {
            if (v > 2) continue; // Error "Continue outside loop"
        }
        dothings(i);
        trace(i);
    }
}
RblSb commented 3 months ago

I'm not sure if this is good syntax. Should inline functions differ from ordinary ones in their logic? I think it would be better to return a Bool from it here and do a if (foo(i)) continue; at the loop level. Probably not detected by null safety and early returns before too.

yuxiaomao commented 3 months ago

Indeed, your syntax makes more sens to me. I'm also surprised by the fact that we can use break / continue inside inline function - before.

yuxiaomao commented 3 months ago

Hum but this one does not compile

static public function main() {
    for (i in 0...5) {
        inline function dothings(v:Int) {
            if (v > 3) {
                if (v > 4) {
                    return true; // Error "Cannot inline a not final return"
                }
            }
            if (v > 3 && v > 4) {
                return true; // Ok
            }
            return false;
        }
        if (dothings(i)) continue;
        trace(i);
    }
}
yuxiaomao commented 3 months ago

Never mind, "inline not final return" error when we have 2 if instead of 1 with && is strange but acceptable, and is not related to this problem.