Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bug: Invalid enum members modifiers #2630

Merged
merged 3 commits into from
Oct 12, 2018

Conversation

Egor18
Copy link
Contributor

@Egor18 Egor18 commented Oct 5, 2018

Hi. I found out that Spoon is probably wrong about the 'final' and 'public' modifiers of enum members.
Consider the following code:

public enum MyEnum {
    ONE,
    TWO,
    THREE;

    private static int len = -1; // Spoon says that len is final and public, but it is not!

    public static void f() {
        len = 44;
    }
}

BTW, If I do the same in a class it works fine:

public class MyClass {

    private static int len = -1; // len is not final and is not public (as expected)

    public static void f() {
        len = 44;
    }
}

This PR contains failing test cases (see lenField.isFinal() and lenField.isPublic()).
Any ideas how to fix this?
Thanks.

@tdurieux
Copy link
Collaborator

tdurieux commented Oct 8, 2018

It seems to be related to this, I will double check:

if (fieldDeclaration.binding.declaringClass != null && fieldDeclaration.binding.declaringClass.isEnum()) {
//enum values take over visibility from enum type
//JDT compiler has a bug that enum values are always public static final, even for private enum
field.setExtendedModifiers(getModifiers(fieldDeclaration.binding.declaringClass.modifiers, true, false));
} else {
field.setExtendedModifiers(getModifiers(fieldDeclaration.binding.modifiers, true, false));
}

@Egor18 Egor18 closed this Oct 10, 2018
@Egor18 Egor18 reopened this Oct 10, 2018
@monperrus
Copy link
Collaborator

LGTM. Ready for merge?

@Egor18
Copy link
Contributor Author

Egor18 commented Oct 12, 2018

Yes, I hope this fix helps.

@pvojtechovsky pvojtechovsky merged commit 3f8427c into INRIA:master Oct 12, 2018
@pvojtechovsky
Copy link
Collaborator

Thank You Egor ;-)

@Egor18 Egor18 deleted the invalidEnumMembersModifiers branch October 31, 2018 09:02
@Egor18 Egor18 restored the invalidEnumMembersModifiers branch October 31, 2018 09:02
@Egor18 Egor18 deleted the invalidEnumMembersModifiers branch October 31, 2018 09:03
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants