goawk
                                
                                 goawk copied to clipboard
                                
                                    goawk copied to clipboard
                            
                            
                            
                        Incorrect parsing of complex ++ expressions
Two cases:
- echo 2 3 4 | goawk '{ $$0++; print $0 }'prints- 2 4 4instead of- 3. I think this is happening because we parse this as- ($($0))++rather than- ($($0++)).
- BEGIN { $0="3 4 5 6 7 8 9"; a=3; print $$a++++; print }gives a parsing error instead of printing- 7\n3 4 6 6 8 8 9.
There are two commented-out (TODO) tests in interp/interp_test.go for this, as well as a commented-out Gawk test (parse1).
I've started playing with this on the fix-incr-decr branch.
Can you walk through what is supposed to happen in 1? I don't understand it, sorry.
gawk, original-awk, and mawk all print 3 for that example. It's because they parse the expression as $0++ (which returns the current value of $0 but also post-increments $0); then the outer $ does fetches $2 but drops the result.
Whereas GoAWK parses it differently, so executes the inner $0 first (which is 2 3 4), then another $, which fetches the second field 2 (the 3), then the ++ increments that field, creating 2 4 4.
So it's a parsing/precedence issue. Hope that helps!
That helps a lot, thanks!
Was this solved by the newest release? Specifically https://github.com/benhoyt/goawk/pull/172
@vegarsti No, unfortunately not -- this is a different issue.
Okay!
This also produces wrong results:
./goawk 'BEGIN { $0="3 4 5 6 7 8 9"; a=3; print ($($a++)++); print $0; print a }' prints  7\n3 4 7 6 7 8 9\n3, whereas
gawk 'BEGIN { $0="3 4 5 6 7 8 9"; a=3; print ($($a++)++); print $0; print a }' prints 7\n3 4 6 6 8 8 9\n3