Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345239 - [1.7][compiler] Compiler should issue better diagnostics for use of <> with anonymous classes
Summary: [1.7][compiler] Compiler should issue better diagnostics for use of <> with a...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-10 05:33 EDT by Srikanth Sankaran CLA
Modified: 2011-08-05 02:54 EDT (History)
3 users (show)

See Also:


Attachments
Proposed patch + tests (15.21 KB, patch)
2011-05-11 01:22 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2011-05-10 05:33:47 EDT
BETA_JAVA7 head of branch.

public class X<T> {
		X<String> x = new X<>() { };
}

The program above elicits the error message:

"Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>"

We could issue a better message that informs the user that his/her attempt to
use <> with anonymous classes is disallowed.
Comment 1 Ayushman Jain CLA 2011-05-10 06:13:56 EDT
This was already part of the initial implementation for the diamond construct in bug 339478 comment 2.
		"2. ERROR in X.java (at line 3)\n" + 
		"	X Test = new X<>(){\n" + 
		"	             ^\n" + 
		"Empty type argument list cannot be used in anonymous class declaration\n" + 
		"----------\n"
Comment 2 Srikanth Sankaran CLA 2011-05-11 01:22:38 EDT
Created attachment 195296 [details]
Proposed patch + tests

Patch under test. Note that prior to this patch, we were rejecting
the illegal programs correctly. Now the message makes it explicit to
the user that diamond cannot be used with anonymous classes.
Comment 3 Srikanth Sankaran CLA 2011-05-11 04:27:51 EDT
Released in BETA_JAVA7 branch.
Comment 4 Deepak Azad CLA 2011-07-19 06:39:20 EDT
Verified with v20110714-1300.