PY-992 Extract Method doesn't handle conditional returns correctly

This commit is contained in:
Oleg Shpynov
2010-06-16 18:24:07 +04:00
parent 5a1588251f
commit da1b499091
3 changed files with 18 additions and 3 deletions
@@ -100,9 +100,12 @@ public class PyCodeFragmentUtil {
for (Instruction outerInstruction : outerInstructions) {
// Here we check control flow when for statement content is beeing extracted
if (outerInstruction instanceof ReadWriteInstruction &&
PyForStatementNavigator.getPyForStatementByIterable(outerInstruction.getElement())!=null){
errorFound = false;
break;
PyForStatementNavigator.getPyForStatementByIterable(outerInstruction.getElement())!=null) {
// In case when return instruction is inside
if (!returnInstructionInside){
errorFound = false;
break;
}
}
}
if (errorFound){
@@ -0,0 +1,7 @@
class Conference(object):
def __init__(self):
self.talks = []
def getTalkAt(self, hour):
for start, end, name in self.talks:
<selection>if hour >= start and hour < end: return name</selection>
@@ -126,4 +126,9 @@ public class PyExtractMethodTest extends LightMarkedTestCase {
public void testClass() throws Throwable {
doTest("context/class.before.py", "bar", "context/class.after.py");
}
public void testConditionalReturn() throws Throwable {
doTest("conditionalreturn.before.py", "bar", "Cannot perform refactoring when execution flow is interrupted");
}
}