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

- ruby*.y: fixed context inside lambda args and module. #709

Conversation

iliabylich
Copy link
Collaborator

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:

  1. ->(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.

  2. 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 special get_context macro-like node that grabs snapshot of the parser.context.

Previously we didn't push a context for module and lambda arguments and so we didn't reject some code.
However, examples that should've raised errors are complicated and it's very unlikely that any code was affected.

Examples of code that is accepted/rejected differently after this change:
1. ->(a) { module M; _1; end }
We didn't push context for module M, and so argument `a` conflicted with implicit parameter `_1`.

2. 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.
@iliabylich iliabylich changed the title - *.y: fixed context inside lambda args and module. - ruby*.y: fixed context inside lambda args and module. Jun 11, 2020
@iliabylich iliabylich merged commit bc20734 into whitequark:master Jun 11, 2020
@iliabylich iliabylich deleted the fix-context-for-lambda-args-and-module branch June 11, 2020 11:19
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

Successfully merging this pull request may close these issues.

None yet

1 participant