zhong-j-yu / rekex

PEG parser generator for Java 17 - grammar as algebraic datatypes
Apache License 2.0
59 stars 6 forks source link

Annotations should allow ElementType=FIELD for use in singleton enums. #8

Closed raptor494 closed 3 years ago

raptor494 commented 3 years ago

When I try to add an @Str or @Ch annotation to an enum field, I get "Syntax error: Type annotations are illegal here." This is probably because those annotations are not declared with @Target including ElementType.FIELD (for enum fields)

Screen Shot 2021-09-27 at 12 03 15 PM
zhong-j-yu commented 3 years ago

Sorry about that. Which version of Java are you using?

I was aware of the ambiguity of type annotation on enum field; but it worked (on my machine:)

zhong-j-yu commented 3 years ago

https://github.com/zhong-j-yu/rekex/blob/main/doc/note-misc.txt

If a enum field is annotated with an anno of @Target=Type_USE, it's not clear what happens. Javac allows it, so it appears that it applies on the type of the field. But field.getAnnotatedType() does not contain the anno. And field.getDeclaredAnnotations() does contain the anno.

zhong-j-yu commented 3 years ago

I think I understand the problem. It is your IDE that reports the error. Since JLS isn't clear on this issue, the IDE cannot be blamed for it. Thanks for reporting.

The issue is fixed in version 1.1.1 - could you try again and see if it works?

zhong-j-yu commented 3 years ago

Hi @raptor494 , if you have no objections, I'll close this issue as fixed in 24 hours.

zhong-j-yu commented 3 years ago

Fixed and available since v1.1.1.