Community
Participate
Working Groups
Build Identifier: 20110916-0149 Reproducible: Always Steps to Reproduce: 1. Invoke the Extract Method refactoring by selecting the statements marked in the code below: ---- public class C { private int m() { int a; int b; // START SELECTION a = 1; b = 2; // END SELECTION return a + b; } } ---- 2. The refactoring tool will report the following message and prevent the user from continuing the refactoring: "Ambiguous return value: Selected block contains more than one assignment to local variables. Affected variables are: int a, int b" CodingSpectator <http://codingspectator.cs.illinois.edu> recorded the messages that the Eclipse refactoring tool reported to our participants. The above error message was the most frequent message that the Extract Method refactoring reported to our participants (See Bug 365129 for more information). I'd like to propose a small change to the above error message to make it easier to understand. The cause of the above message isn't just the selection of assignments to multiple local variables. Rather, the problem is that the selected block contains assignments to multiple variables that are used outside the selection. For example, the Extract Method refactoring won't report any messages in the code below. ---- public class C { private int m() { int a; int b; // START SELECTION a = 1; b = 1; // END SELECTION return a; } } ---- How about changing the above message to the following? "Ambiguous return value: Selected statements contain more than one assignment to local variables that are used in the code following the selection. Affected variables are: int a, int b"
(In reply to comment #0) > How about changing the above message to the following? > > "Ambiguous return value: Selected statements contain more than one assignment > to local variables that are used in the code following the selection. Affected > variables are: int a, int b" While it is not hard to figure out why assignment to local variables is a problem, it does take some brain cycles and I do not see any harm in adding a few extra words to make this explicit.
While this message is correct, it feels a bit too long. "Ambiguous return value: Selected block contains more than one assignment to local variables that are used in the code following the selection. Affected variables are: int a, int b" I am leaning towards changing this to.. "Ambiguous return value: Selected block modifies more than one local variable used in subsequent code. Affected variables are: int a, int b"
(In reply to comment #2) > "Ambiguous return value: Selected block modifies more than one local variable > used in subsequent code. Affected variables are: int a, int b" Sounds good to me. Note that this bug is related to Bug 365129.
Fixed in master - 743a83b9b11ae23fa1c57ea45ed9c0901ec464ad