Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

A generic class can't have static fields error when a subclass of Parser is used inside a macro #62

Open
joshtynjala opened this issue Sep 13, 2022 · 3 comments

Comments

@joshtynjala
Copy link

I created a subclass of Parser, and I tried to use it inside a macro. It failed with compiler error "A generic class can't have static fields".

As you can see in #61, I was able to get my Parser subclass working inside a macro by fencing static public macro function parse(). However, I understand that this isn't the correct solution.

I suppose that a similar workaround that I can use for now is to copy all of the code except static public macro function parse() from Parser into a new class, and use that copy instead. However, I would prefer to use the real Parser so that I don't need to manually merge any changes that you make to hxparse in the future.

@joshtynjala
Copy link
Author

joshtynjala commented Sep 13, 2022

Another workaround that seems to work for me is to fence the @:generic meta, while keeping static public macro function parse().

#if !macro
@:generic
#end

@joshtynjala
Copy link
Author

Just in case it's relevant, my use-case is creating a custom parser for some kind of markup language. The idea is that I would use this parser in a macro to dynamically generate a TypeDefinition and call Context.defineType().

@Simn
Copy link
Owner

Simn commented Sep 13, 2022

Another workaround that seems to work for me is to fence the @:generic meta, while keeping static public macro function parse().

#if !macro
@:generic
#end

That looks like a good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants