Opened 4 years ago

Closed 4 years ago

#1330 closed defect (fixed)

spock generates unreachable code

Reported by: Mario Domenech Goulart Owned by: felix winkelmann
Priority: major Milestone: someday
Component: extensions Version: 4.11.0
Keywords: spock, unreachable code Cc:
Estimated difficulty:

Description

The spock runtime (both spock-runtime.js and spock-runtime-debug.js) contains unreachable code. Example:

 ____25call_2dwith_2dsaved_2dvalues = t1355;	// set! %call-with-saved-values
...
    var t6 = t1358;
    var t1360;
    if(t6 !== false) {
     return k1100(t6);
     t1360 = undefined;
    }
...

The assignment t1360 = undefined; is never reached, as there is a return statement immediately before.

Tip to find such cases: search for " = undefined" in spock-runtime.js or spock-runtime-debug.js.

I don't know exactly how this affects code, but the firebug console prints thousands of warnings because of this.

Attachments (1)

spock-dead-assign-undefined.diff (583 bytes) - added by felix winkelmann 4 years ago.

Download all attachments as: .zip

Change History (5)

Changed 4 years ago by felix winkelmann

comment:1 Changed 4 years ago by felix winkelmann

Can you try the attached Patch? The reason for these assignments is that the compiler does not detect whether conditional branches return. The patch avoids an assignment to variable if the branch has an unspecified result. The variable declared before the conditional (holding the result of either branch) is initialized to undefined anyway, so this should work as before.

There may be more cases of dead assignments, but this patch should eliminate most.

comment:2 Changed 4 years ago by Mario Domenech Goulart

Thanks, Felix. You patch seems to do the trick.

comment:3 Changed 4 years ago by felix winkelmann

Very good, I'll push a new version, together with your fix from #1331

comment:4 Changed 4 years ago by felix winkelmann

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.