grain icon indicating copy to clipboard operation
grain copied to clipboard

Function call argument locations `paa_loc` are further to the left than expected

Open ospencer opened this issue 1 year ago • 1 comments

This may be because the whitespace is being counted.

ospencer avatar Jan 23 '24 22:01 ospencer

I did some digging on this and specifically it seems to be that the pos_end of the pexp_loc is one position behind in the nested binop case. That's at least the only case with varying inputs I could find, in the stdlib we this statement in number.gr triggers it x+=c[i]/(z+i), I dove into this a little and at first I thought it might be the binop loc calculation logic here ~~interesting removing it branch here fixes the issue and both the stdlib and test suite both pass formatting checks. I didn't want to make a pr though without context on the location difficulties that formula referred too?~~

What I think is actually happening here is related to the (z+i), specifically when we parse x+=(10) we parse it as x=x+(10) but we don't represent parens in our ast, so what happens is x+(10) has the length to the the closing paren but because we are calculating binop length using the ast we see as to the 0. ~~It seems we can just remove the code to calculate it normally but I didn't want to make a pr without the context.~~

I went back the pr #1271 when it was introduced and I can't reproduce the loc not equaling our calculated loc except in the paren case even with the source from the original issue, so i'm wondering if another change has corrected the original problem with the first issue or something.

spotandjake avatar Apr 17 '25 22:04 spotandjake