manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.43k stars 125 forks source link

[Bug] compile-time error when having multiple classes in the same file #484

Closed CC007 closed 1 year ago

CC007 commented 1 year ago

Describe the bug When using multiple classes in one source file (one being public, the rest package-private, like is allowed in Java), I get the following compile-time error:

java: java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol$VarSymbol.getAnnotation(java.lang.Class)" because "tree.sym" is null

To Reproduce Steps to reproduce the behavior: compile code from gist

Expected behavior I expected these classes to compile as if they were package-private classes that were specified in separate files, with all Manifold features working without issue.

Screenshots afbeelding

Desktop (please complete the following information):

Additional context See gist: https://gist.github.com/CC007/13c6211b20c3c64dfb023415fc98cf2c The code here uses manifold-props, but I also noticed a ... because "tree.sym" is null error when using other manifold dependencies.

rsmckinney commented 1 year ago

Unfortunately, "piggyback" classes are not supported. This feature of Java is a pet peeve of mine; manifold will probably never support it. Sorry this tidbit is missing from the documentation.

CC007 commented 1 year ago

I expected as much. Just tried to use it, because java's nested class field access rules are a bit wack and prevented me from demoing how the Private and Protected parameter for manifold-props annotations work, so I tried to use these. I'll just use a package with multiple source files instead then.

rsmckinney commented 1 year ago

I'll just use a package with multiple source files instead then.

Right. Or, you can use static inner classes, whichever is most suitable. In my view piggyback classes are pointless at best. :/

CC007 commented 1 year ago

That's what I meant with nested classes above. Field access is unintuitive, considering you can access private fields defined in nested classes both from the parent and from sibling classes. It has its uses, but it wasn't suitable for my use-case