Summary: | [1.5][compiler] Access to static fields within enum constructors inconsistent with javac | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Jon Skeet <skeet> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | VERIFIED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | forax, jleone, mlists, nick_lerissa, reg.ecbz, zorzella |
Version: | 3.1 | ||
Target Milestone: | 3.1.1 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Jon Skeet
2005-06-24 15:35:57 EDT
Indeed this seems to be a bug in Eclipse compiler. From the JLS (page 257), It is a compile-time error to reference a non-constant (ยง15.28) static field of an enum type from its constructors, instance initializer blocks, or instance variable initializer expressions. Only implicit references are forbidden, following would be fine: public enum Test { SomeValue; static int asd; private Test() { Test.asd=5; } } Aha - that's good to know, thanks :) Note that qualified references may yield default values for fields, it simply bypasses the normal initialization. e.g. class X { static int FOO = X.BAR; static int BAR = 2; } --> FOO will be 0. Clarifying: it actually bypasses the check for initialization. Added EnumTest#test115-116. Fixed. Will be released to 3.1 maintenance branch as soon as it is created. Fix is in Scope#getBinding(char[]...), it ensures that when finding a static field in enum, it isn't located inside offending context. Fixed in 3.1 maintenance branch *** Bug 102265 has been marked as a duplicate of this bug. *** *** Bug 92165 has been marked as a duplicate of this bug. *** Verified in 3.2 M1 with build I20050808-2000. *** Bug 108905 has been marked as a duplicate of this bug. *** *** Bug 110403 has been marked as a duplicate of this bug. *** Verified using M20050923-1430 for 3.1.1 *** Bug 149042 has been marked as a duplicate of this bug. *** |