Summary: | is double "; " on a return statement an error? | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Rodrigo Peretti <rodrigo> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | RESOLVED WONTFIX | QA Contact: | |
Severity: | minor | ||
Priority: | P3 | CC: | lattam |
Version: | 2.0 | ||
Target Milestone: | 2.0 M4 | ||
Hardware: | PC | ||
OS: | Windows 2000 | ||
Whiteboard: |
Description
Rodrigo Peretti
2002-03-12 17:30:04 EST
';' represents an empty statement. So this statement is unreachable after a return. So if you write: Object myObject = new Object();; The first semi-colon closes the local declaration statement and the second semi-colon is simply an empty statement. You can perfectly write this. When you write: return myObject();; The first semi-colon closes the return statement and the second one is an empty statement. The JLS specifies that all statements must be reachable (http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#236365). In your example, the first empty statement is reachable, because a field declaration doesn't exit the method. However the second empty statement is unreachable, because the flow of the execution will never reach it. It is after a return statement and this statement exits the method. So as the JLS specified, the compiler returns an error saying that this empty statement is unreachable. If you double-click on the error in the task view, you will have the second semi- colon highlighted, which means this is the unreachable code. Some compilers were ignoring this error. Now we correctly reject such a code. Changing the error message for something like "duplicate semi-colon after return statement" would be wrong. This message is used for all unreachable code. You could write: return myObject;System.out.println(); In this case we flag in the same way the whole statement System.out.println(); has been unreachable. The difference is that this is not an empty statement. So we have a generic message to report unreachable code and as long as we highlight the whole statement (reduced to a single semi-colon in the case of an empty statement) I don't see anything wrong with that. Ok to close? Sure. Empty statements are unfortunately true statements, and have to be reported by the compiler when unreachable. Closing |