Bug 20820 - Squiggly line is at a bad place for missing return statement
Summary: Squiggly line is at a bad place for missing return statement
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-21 13:57 EDT by Curtis d'Entremont CLA
Modified: 2002-09-10 08:50 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Curtis d'Entremont CLA 2002-06-21 13:57:34 EDT
Build 20020621
Win2k

If you try to save a method like this:

int method() {

}
Comment 1 Curtis d'Entremont CLA 2002-06-21 14:02:30 EDT
Oops! here's what I meant to say..

int method() {
  int field = 2;
}

Try to save this, and a squiggly line appears under "field". The error message 
says that you forgot to return something. Without looking at the error message, 
it's somewhat misleading because it's telling you there's something wrong with 
field, which is not true. I would like to see the squiggly line under the "int" 
in the method signature.

If the squiggly line was meant to go under field, and this isn't a bug, then 
consider this a request.
Comment 2 Erich Gamma CLA 2002-06-23 17:11:22 EDT
Moving to JDT CORE for post 2.0 consideration
Comment 3 Philipe Mulet CLA 2002-06-24 07:20:48 EDT
Last statement is intended to be blamed. Error positioning need some tuning in 
this scenario.

Not critical for 2.0
Comment 4 Philipe Mulet CLA 2002-07-04 17:52:08 EDT
Source position issue
Comment 5 Olivier Thomann CLA 2002-07-24 11:47:24 EDT
We might simply want to tag the method name in all cases. Right now if a method
has no statement and its return type is different from void, we tag the method
name. It might be more consistent to do this all the time instead of tagging the
last statement when a method has statements.
Comment 6 Curtis d'Entremont CLA 2002-07-24 12:23:10 EDT
If the line were to go under the entire method signature then that would be ok, 
because there IS something wrong with what's underlined. Ideally, I think the 
best place to put it is directly on the return type, because that's where the 
problem really is. 

Having the line only on the method name would be better than what we have now, 
but I think it could be misleading to some. It indicates there is something 
wrong with the name itself, which is not actually true..
Comment 7 Olivier Thomann CLA 2002-07-24 12:31:01 EDT
Your last statement is incorrect. The location of the error doesn't prevent the 
user from reading the error message. And the error message clearly states that 
the problem is that this method doesn't return the proper type.
Comment 8 Curtis d'Entremont CLA 2002-07-24 14:01:38 EDT
We should get more opinions on this..
To everyone I just added: Where would you prefer to see the squiggly line?
Comment 9 John Arthorne CLA 2002-07-24 14:25:22 EDT
I actually prefer the current behaviour.  The last statement is at fault because 
it should be a return statement, or should be followed by a return statement.  
There's nothing wrong with the method signature, so a squiggly line under the 
method signature is no more useful than the current behaviour.  I think it could 
be improved in some cases though.  For example, if the last statement is a 
compound statement, it currently underlines the first letter of the statement 
keyword (if, try, while, etc), but it would be clearer (at least to me) to 
underline the last simple statement inside the compound statement.
Comment 10 Olivier Thomann CLA 2002-07-24 15:12:26 EDT
John, this would not be enough. Even if you return from the last statement of a 
if statement. You might not garantee that all paths are returning the proper 
type.
For example:
    int method() {
    		boolean b = true;
    		if (b) {
    			return 0;
    		}
    }
Then you end up with the same problem. The guilty statement is the "if", not 
the last statement of the compound statement.
I think that finally the current behavior is not that bad. There is no perfect 
solution and the error message is really clear. "This method must return a 
result of type ...".
Even if we tag the return type in the method header, it is not better, because 
there is nothing wrong with the return type.
Comment 11 John Arthorne CLA 2002-07-24 15:29:59 EDT
Ok, non-branching compound statements then ;)  I find try blocks are the worst 
case - it underlines the "t" in try, even though the last expression is nowhere 
near it.  In any case, I have no real problem with the current behaviour.
Comment 12 Curtis d'Entremont CLA 2002-07-24 15:38:28 EDT
I guess it depends what you consider to be right, the code or the method 
signature. It's possible that the programmer wrote 'int' instead of 'void' for 
return type, and it's also possible that he/she forgot the return type.. but 
there's no way to know which case it is. I think the problem is that we're 
forced to put the line on something which is correct.. because the problem 
isn't that something there is wrong, it's that something isn't there at all..

If no one else has a problem with this behavior we can just throw this PR in 
the garbage..
Comment 13 Olivier Thomann CLA 2002-07-24 16:13:36 EDT
Ok, I close it as "WONTFIX" since this is not really a problem and there is no
perfect solution for it. We will always find somebody who doesn't like the way
we did it <g>.