Bug 88223

Summary: [1.5][compiler] Local enums are not reported as error
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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