Bug 8384 - Unexpected compile errors when abstract method missing return type
Summary: Unexpected compile errors when abstract method missing return type
Status: RESOLVED FIXED
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.0 M3   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 8789 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-01-24 11:35 EST by John Arthorne CLA
Modified: 2002-02-11 04:52 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2002-01-24 11:35:52 EST
Define this class:

public abstract class Agent {
	public abstract String talk();
	
	
	public abstract listen(String message);
}

When compiled, two errors show up.  Against the talk() method, it says "Abstract 
methods do not specify a body."  Against the listen() method, it says "Syntax 
error on token ";", "{" expected."

The first error message is wrong, because there is no problem with the 
definition of the talk method.  On the second method, it seems to interpret the 
abstract keyword as the return type, and then complains that there is no method 
body.  Shouldn't it be able to detect and report that the return type is 
missing?
Comment 1 Philipe Mulet CLA 2002-01-25 07:19:27 EST
The only parsing rules which can digest a missing return type method is a 
constructor one, which cannot be abstract and thus expects a block body (not a 
semi-colon one).

This explains the parse error (we could investigate improving this).

The first error though is more embarrassing.
Comment 2 Philipe Mulet CLA 2002-01-25 07:38:33 EST
First reported error is due to the fact our syntax recovery did not position 
the bit for semi-colon body method, thus fooling the method check later on.
This one is fixed.

Now I obtain the following 2 errors:

----------
1. ERROR in d:\Agent.java (at line 7)
	public abstract listen(String message);
	                ^^^^^^^^^^^^^^^^^^^^^^
Return type for the method is missing
----------
2. ERROR in d:\Agent.java (at line 7)
	public abstract listen(String message);
	                                      ^
Syntax error on token ";", "{" expected
----------

I agree that the second one isn't very helpful, but the proper diagnosis is on 
the number one (and the second could be discared with a parser change: tolerate 
constructor with semi-colon body).

I think this latter change is interesting anyway, since it will improve our 
behavior for recovery in general.
Olivier - can you please investigate if this grammar change is breaking 
anything (still no ambiguity as I would expect).
Comment 3 Philipe Mulet CLA 2002-01-25 07:48:26 EST
Regression test added (NegativeTests.test253), will need to be tuned after 
complete fix (with grammar change).
Comment 4 Olivier Thomann CLA 2002-01-29 16:20:28 EST
The second error is gone after changing the grammar to consume silently the 
constructor without a body. See consumeInvalidConstructorDeclaration on the 
Parser.
Released in HEAD. All tests are green and the NegativeTests.test253 has been 
updated to remove the second error.
Comment 5 Philipe Mulet CLA 2002-01-31 05:53:40 EST
*** Bug 8789 has been marked as a duplicate of this bug. ***