-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add erl_anno:set_end_location/2 #8966
Conversation
CT Test Results 2 files 96 suites 1h 7m 1s ⏱️ Results for commit fa58d2c. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
false -> | ||
undefined; | ||
{location, Location} -> | ||
{end_location, erl_anno:end_location(erl_anno:set_text(Text, erl_anno:new(Location)))} |
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.
The end_location
is a bit tricky in the current tests setup, because it's both primary and secondary part of anno. In order to accommodate this, here we need to infer the value here (similarly to the clause for line
above). Duplicating the whole text scan logic from the actual implementation sounds weird, so I call the inference directly.
I am happy to revise the tests, if another approach is preferable :)
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.
great addition
It is not clear to me from the discussion in #8945 who would actually call So what I'm asking whether this new function would be useful without also updating the scanner and/or parser. @jhogberg and I looked at #3026 and thought it would be useful to implement something like that to be able to provide better compiler messages and warnings, but we might want to implement in a slightly different way (with less heuristics). However, it is unlikely that will happen before Erlang/OTP 29. |
This would not be used by the scanner but it could be used by the parser. The issue today is that we only keep token information from the scanner, but if we want to know the whole range of a function clause, we can't store that today. By adding this, we would allow the parser to annotate the end location (based on the |
This looks good to me. Please squash the commits and force-push. |
fa58d2c
to
16ead33
Compare
Done! |
See the discussion in #8945 (comment).
Currently
erl_anno:end_location(Anno)
is inferred fromlocation
andtext
(if present). However, this means that in order to store a location range, we always need to store the whole text. This allows settingend_location
ofAnno
directly.With this change
erl_anno:end_location(Anno)
will first look forend_location
set directly and then fallback to the inference if applicable.