Bug 88223 - [1.5][compiler] Local enums are not reported as error
Summary: [1.5][compiler] Local enums are not reported as error
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-16 14:13 EST by Olivier Thomann CLA
Modified: 2005-03-30 19:12 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 Olivier Thomann CLA 2005-03-16 14:13:02 EST
This code should not compile, but it does.

public class X {
	void foo() {
		class Local {
			enum E {
				C, B;
			}
		}
	}
	void bar() {
	}
}

If the enum type is static, we report an illegal modifier.

javac reports:
X.java:4: enum declarations allowed only in static contexts
                        enum E {
                        ^
X.java:5: non-static variable this cannot be referenced from a static context
                                C, B;
                                ^
X.java:5: non-static variable this cannot be referenced from a static context
                                C, B;
                                   ^
3 errors

I would say we should simply report the first error.
Comment 1 Philipe Mulet CLA 2005-03-16 16:15:38 EST
When adding enum support, I remember wondering about local enums as well. 
Once rejected, you should also fix up ClassScope#checkAndSetModifiers() which is
handling them.
Comment 2 Olivier Thomann CLA 2005-03-17 10:05:45 EST
Kent, we should check that enums are always defined in a static context.
class X {
    class Y {
        enum E {}
    }
}

is illegal, but:
class X {
    static class Y {
        enum E {}
    }
}
is legal.
Comment 3 Kent Johnson CLA 2005-03-17 12:38:48 EST
Added EnumTest test082
Comment 4 Olivier Thomann CLA 2005-03-30 19:12:51 EST
Verified in 20050330-0500