-
Notifications
You must be signed in to change notification settings - Fork 186
Make it = it assign nil to match parse.y behavior [Bug #21139]
#3604
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
Changes from 1 commit
cf3bbf9
a6b448b
659d769
51e2b04
fb136c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 42.tap { it = it; p it } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the comment. You're right, that test case would be good to have as well. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,25 @@ def test_it_block_parameter_syntax | |
| assert_equal(it_block_parameter_sexp, actual_ast.to_sexp) | ||
| end | ||
|
|
||
| def test_it_assignment_syntax | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for the parser gem translation and is not necessary to add as a test. The fixture you added should generate a snapshot instead that you should commit to test the prism behaviour.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for pointing this out.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I run Started
|Created snapshot at /home/user/code/ruby-prism/snapshots/it_assignment.txt.
-Created snapshot at /home/user/code/ruby-prism/snapshots/it_read_and_assignment.txtThose basically contain the test I commented on here, just with the native prism ast format. This is automatically tested against and when the output changes, a test would fail.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the comment. |
||
| it_assignment_fixture_path = Pathname(__dir__).join('../../../test/prism/fixtures/it_assignment.txt') | ||
|
|
||
| buffer = Parser::Source::Buffer.new(it_assignment_fixture_path) | ||
| buffer.source = it_assignment_fixture_path.read | ||
| actual_ast = Prism::Translation::Parser34.new.tokenize(buffer)[0] | ||
|
|
||
| it_assignment_sexp = parse_sexp { | ||
| s(:block, | ||
| s(:send, s(:int, 42), :tap), | ||
| s(:args), | ||
| s(:begin, | ||
| s(:lvasgn, :it, s(:lvar, :it)), | ||
| s(:send, nil, :p, s(:lvar, :it)))) | ||
| } | ||
|
|
||
| assert_equal(it_assignment_sexp, actual_ast.to_sexp) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def assert_equal_parses(fixture, compare_asts: true, compare_tokens: true, compare_comments: true) | ||
|
|
||
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.
Do we not need to append to the list of implicit parameters still? For example, in this scenario:
The block still needs to have an implicit
itparameter as the first print is reading from it. And this matches parse.y.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.
Thank you for your feedback.
I applied this change to Ruby and tested the behavior you mentioned, and the result is:
The implicit parameter works correctly for the first it read, and the assignment properly creates a local variable it. So, no additional changes are needed for the implicit parameters list.