-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Implement support for optional getters #1576
Conversation
This analysis is required for proper code generation in the TypeScript target when strict null checks are enabled. It also applies to targets intending to differentiate optional values from required values.
Looks interesting. do we have a few examples that exercise this stuff? i guess we have one issue you just resolved, right? |
@parrt I used this to fix tunnelvisionlabs/antlr4ts#265. That issue includes an example which highlights the difference in the generated code produced by this target. I also mentioned optional values. In a hypothetical modified Java target, one could use |
@parrt The Swift target may also benefit from this change, but I don't know enough about its handling of nullable types to say for sure. It does appear that the |
@@ -134,6 +183,11 @@ protected void exitSubrule(GrammarAST tree) { | |||
for (Map.Entry<String, MutableInt> entry : frequencies.peek().entrySet()) { | |||
entry.getValue().v = 2; | |||
} | |||
|
|||
int multiplier = tree.getType() == POSITIVE_CLOSURE ? 1 : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change this to a boolean rather than a multiplier? ;) Ain't that fortran66 style hahah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified this even more 😄
This analysis is required for proper code generation in the TypeScript target when strict null checks are enabled. It also applies to targets intending to differentiate optional values from required values.