- ruby*.y: fixed context inside lambda args and module. #709
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.
Previously we didn't push context for module and lambda arguments and so we didn't reject some code (or we rejected what's allowed).
However, examples that should've raised errors are complicated and it's very unlikely that any code was affected. At least no related issues were reported.
Examples of code that is accepted/rejected differently after this change:
->(a) { module M; _1; end }
We didn't push context for module M, and so argument
a
conflicted with implicit parameter_1
. In Ruby module opens a new scope and so_1
is just a regular local variable.class A; ->(a = (return; 1)) {}; end
This code is valid, because
return
is a part of the lambda. But we didn't store this fact internally, and so it was rejected before.Both examples described above (and all similar variations) are fixed in this commit.
Also, I've slightly improved assertions related to context (
assert_context
). Instead of checking state of the half-reduced AST (which is impossible for lambda args for example) we use a specialget_context
macro-like node that grabs snapshot of theparser.context
.