Bug 80066 - [1.5] local enum declarations
Summary: [1.5] local enum declarations
Status: RESOLVED DUPLICATE of bug 87818
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-02 17:31 EST by Jim des Rivieres CLA
Modified: 2005-03-17 09:53 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jim des Rivieres CLA 2004-12-02 17:31:11 EST
Build 20041201:

The following legal J2SE5 program
public class Test {
	public static void main(String[] args) {
		enum Count {}
	}
}

compiles with the following error
Syntax error on token "enum", interface expected

There are 2 problems:
(1) the error message is misleading - "interface" is definitely *never* 
expected in a block

(2) local enum declarations appear to be legal. According to the grammar rules 
in JLS3 14.2, 

BlockStatement:
  LocalVariableDeclarationStatement
  ClassDeclaration
  Statement

and in 8.1,

ClassDeclaration:
  NormalClassDeclaration
  EnumDeclaration

I can't see any mention in the spec that they are illegal.

java_1_5.g is not currently handling this case.
Comment 1 Olivier Thomann CLA 2004-12-03 10:09:28 EST
Jim, javac reports:
X.java:3: enum types must not be local
                enum Count {}
                ^
1 error
Comment 2 Olivier Thomann CLA 2004-12-03 10:15:48 EST
Page 255, look at the discussion topic.
"This implies that it is impossible to define a local enum , or to define an
enum for an inner class.
So I would keep it as is for now.
Comment 3 Olivier Thomann CLA 2004-12-03 10:36:46 EST
David,

Please add the same support than for invalid local interfaces. The code is
illegal, so this is not a priority, but adding the same support could allow us
to improve the error message.
Comment 4 Olivier Thomann CLA 2005-03-17 09:53:27 EST

*** This bug has been marked as a duplicate of 87818 ***