Community
Participate
Working Groups
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.
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.
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.
Added EnumTest test082
Verified in 20050330-0500