Sei-Lisa / LSL-PyOptimizer

Optimizes a LSL2 script, folding constants, removing unused code and more. Adds new syntax features too.
GNU General Public License v3.0
35 stars 11 forks source link

Jump statements with default returns delete the required return value #14

Closed Tonaie closed 4 years ago

Tonaie commented 4 years ago

This is a little of a special case because jump statements are rarely used but take this function for an example:

list out(){
    integer n = 3;
    @continue;
    llOwnerSay((string)n);
    --n;
    if( !n )
        return [];
    jump continue;
    return [];    
}

After optimizing:

list _()
{
    integer loc_n = 3;
    @J_autoGen00001;
    llOwnerSay((string)loc_n);
    --loc_n;
    if (!loc_n)
        return [];
    jump J_autoGen00001;
    // Note that return []; was removed here
}

Even though the return []; at the end of the original function is never reached because of the jump statement, LSL requires it in order to compile.

Sei-Lisa commented 4 years ago

Thanks a lot, and that was a nice test case! I've added it to the test suite, please let me know if that's a problem for you.

Sei-Lisa commented 4 years ago

Oops, I pressed the send button too soon.

There were several problems here:

The fix is already committed and applied to the online version.

A test case had to be disabled because this fix brought back a RETURN statement in it.