JavaScript parse tree visitor: check if ctx.children is non-null in visitChildren #2196
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been encountering a problem where the default generated visitor in javascript. It will crash because in the
visit
method it tries to callaccept
on null because it has been passed a null object byvisitChildren
.This seems like a bug to me as the
children
field is expected to sometimes be null as it is initialised to null and only made non-null when a child is added. Other places handle this case explicitly but here it's assumed to be non-null.Making the change in this PR makes my visitor work correctly. Do you think it is the right change to make, or if not what should I be doing instead?
To explain my reasoning on why this change and not any other:
ctx.getChildCount() > 0
and behave the same. I went for this as it's shorter and we're already accessingctx.children
directly instead of usinggetChild
so it seems in keeping with the current code.visit
by changing theelse
toelse if (ctx)
but this seemed a more intrusive way of fixing it and it's entirely reasonable forvisit
to expect a non-null argument.