Withdrawn: 8173165: javac should reject references to enum constants from nested classes inside instance initializers
Guoxiong Li
github.com+13688759+lgxbslgx at openjdk.java.net
Tue Dec 29 14:03:56 UTC 2020
On Tue, 29 Dec 2020 11:19:11 GMT, Guoxiong Li <github.com+13688759+lgxbslgx at openjdk.org> wrote:
> Hi all,
>
> The [JLS 8.9.2](https://docs.oracle.com/javase/specs/jls/se15/html/jls-8.html#jls-8.9.2) states it as bellow.
>
>> It is a compile-time error to refer to a static field of an enum type from a constructor, instance initializer, or instance variable initializer of the enum type, unless the field is a constant variable (§4.12.4).
>
> Currently, compiler doesn't generate the compile-time error when compiling the following code.
>
> import java.util.HashSet;
> public enum Test {
> FOO;
> public HashSet<Test> vals = new HashSet<Test>(){
> Test test = FOO;
> {
> add(FOO);
> }
> };
> }
>
> This patch fixes it and adds two corresponding tests. Thank you for taking the time to review.
>
> Best Regards.
This pull request has been closed without being integrated.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1905
More information about the compiler-dev
mailing list