victorlei / smop

Small Matlab to Python compiler
MIT License
1.08k stars 409 forks source link

Nested elseif statements are being incorrectly translated #140

Open Codeguyross opened 5 years ago

Codeguyross commented 5 years ago

From matlab elseif statements are being incorrectly converted to python

In matlab:

elseif  checkVal(e) < 50 && ...
                        checkVal2(e) == something

Is being convered to this in python

else:
       if checkVal(e) < - 50 and checkVal2(e) == something:

This might look ok but if you have more than one elseif in matlab then the output in python is nesting the elseif statements.

an example of the bad translation to python is

else:
       if checkVal(e) < - 50 and checkVal2(e) == something:
           else:
                   if checkVal(e) < - 50 and checkVal2(e) == something:

to correctly convert this line to python it needs to be converted to

elif checkVal(e) < - 50 and checkVal2(e) == something:

RobBW commented 4 years ago

Sourcery is capable of resolving this sort of issue after the fact. https://sourcery.ai In particular see https://sourcery.ai/blog/explaining-refactorings-3/