-
Notifications
You must be signed in to change notification settings - Fork 67
Fix a bug with named NEVER_MATCH expressions #454
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
Conversation
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.
Unfortunately, the new error also not so good, because it is misleading. The grammar
start 'start' = []
cannot have any expectations because it just cannot match any input. Probably, it would be better to emit compiler error here instead. This grammar does not expect "start" rule at this position, it expect literally nothing. Even EOF is not expected there.
@@ -618,7 +618,7 @@ function generateBytecode(ast, options) { | |||
[op.SILENT_FAILS_ON], | |||
generate(node.expression, context), | |||
[op.SILENT_FAILS_OFF], | |||
buildCondition(match, [op.IF_ERROR], [op.FAIL, nameIndex], []) | |||
buildCondition(-match, [op.IF_ERROR], [op.FAIL, nameIndex], []) | |||
); |
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.
Good catch! The bug probably was introduced during rebase while adapt initial PR to the new code after another merged PR.
Actually, the whole buildSequence
could be replaced by [op.FAIL, nameIndex]
if node always fail and there are no actions or semantic predicates (because they can have side effects), but anyway, it is better to do in a separate pass.
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.
if node always fail and there are no actions or semantic predicates (because they can have side effects)
There are already comments about adding side-effect analysis so we can do that kind of thing...
But that was true whether or not it's a
I guess thats ok if it's a start rule that always fails - but my examples only used start rules to exemplify the problem. You could use it as a catch all where a promising start goes off the rails:
Ok, its still not a great example, but it could be useful to have a |
d0f279c
to
390fc54
Compare
@Mingun did you end up being happy with where this patch is at the moment? |
Yes, please merge. |
I've got a clean rebase on top of main as it sits at the moment. I'm going to try pushing it to @markw65 's branch, which is likely going to fail. If so, I guess I'll start a new PR with my copy of the branch, and try to ensure the authorship is kept intact as much as possible. |
390fc54
to
aa39652
Compare
OK, that looks like it worked. Merging. |
Sorry, I've been occupied elsewhere, but thanks for merging. |
Found while working on #452.
The condition was backwards, so the error got misreported:
Before the fix:
After the fix:
There was already a test, but it was testing for the incorrect result...