| Summary: | [extract method] rejected selection followed by "break" | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Ran Ettinger <ran.ettinger> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | akiezun |
| Version: | 3.1 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | stalebug | ||
*** Bug 109285 has been marked as a duplicate of this bug. *** once this is fixed, the fan website should get updated too :) http://progtools.comlab.ox.ac.uk/projects/refactoring/bugreports/eclipse This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
Trying to apply the Extract Method refactoring on the following selection results in an unnecessary rejection. Original program: private int g(boolean b) { int n = 10; int i = 0; while (i < n) { if (b) { // Extract Method from here i++; n -= i; // to here break; } else i++; } return n; } Applying Extract Method on the selected code (signalled by the comments) results in a rejection with the message: "Ambiguous return value: selected block contains more than one assignment to local variable". In fact, because of the "break" statement, only the modified local variable n should be returned. The local variable i will never be relevant on return from the extracted method. As a result, variable i can be localized in the new method. I expected the refactored source to look like this: private int g(boolean b) { int n = 10; int i = 0; while (i < n) { if (b) { n = newMethod(i, n); break; } else i++; } return n; } private int newMethod(int i, int n) { i++; n -= i; return n; }