Closed csabahenk closed 1 year ago
@csabahenk Reproduced via unparser native self check system:
bundle exec bin/unparser -e 'a.foo(b)' -e 'a&.foo(b)' -e 'a.+(b)' -e 'a+b' -e 'a&.+(b)'
Success: (string)
Success: (string)
Success: (string)
Success: (string)
(string)
Original-Source:
a&.+(b)
Generated-Source:
a + b
Original-Node:
(csend
(send nil :a) :+
(send nil :b))
Generated-Node:
(send
(send nil :a) :+
(send nil :b))
Node-Diff:
@@ -1 +1 @@
-(csend
+(send
Error: (string)
@csabahenk This is fixed in release v0.6.8.
OT: What are you using unparser for? I'm still on the search for the people using unparser so much: https://bestgems.org/gems/unparser its being used outside of mutant a lot, where the known OSS dependencies only attribute for a small fraction. Is that you?
Thanks for the quick fix!
@mbj I tend to accomplish various data mangling tasks with ruby, as shell one-liners or in Irb... These code sinppets exhibit a tendency to grow and at some point the one-liner format becomes unpractical.¹ Then I expand them to a well-indented code sinppet with unparser.
As I find Ruby to be a killer tool for scripting tasks, unparser became a cornerstone of my interactive usage... However, it would be way too sad for unparser if this would be a visible fraction of its usage :)
¹ I can even be mode detailed about where that point usually lies: I picked up the style of writing Ruby from letf to right... rarely editing what was written, just extending the data pipeline. This style can be smoothly practised without hitting a line break. However, if the code logic needs a substantial tweak, I do need to go back to the middle to modify stuff in there... at that point the existing code stuffed in one line looks to be an inpenetrable sigil soup :) So then, unparser to the rescue! (Also with unparser I can mangle the code back to a one-liner (using the property of uparser generated code being semantically resilient to a s/\n/;/g
substitution), so after the tweak I can continue where I left off...)
@csabahenk Hah, thanks for that details. BTW you can run bundle exec unparser **/*.rb
in your ruby files to mass check all files against the round trip property, feel free to bring up any error here. I usually fix all but the freaking dynamic string ones where the AST is not good enough to reproduce.
I doubt you do ~40k downloads/d on your described use case. And I think there is some industrial user out there whom I'd love to get in touch with. If that is real volume from CI etc, I assume they'd love to sponsor this work.
Cheers,
Markus
Versions:
Output:
Expected: unparser renders
a.+(b)
anda&.+(b)
to distinct, pairwise equivalent experssions. Actual: unparser rendersa.+(b)
anda&.+(b)
to the same expression (equivalent only to the former).Note that unparser handles the safe navigation operator properly for "normal" method calls which are not in use as infix pseudo-operators.
I also checked if the bug propagates down to parser:
Output:
Expected: parser parses s
a.+(b)
anda&.+(b)
to distinct ASTs. Actual: meets the expectation.