Fix more declaration ranges#7774
Conversation
|
This is ready. |
KevinRansom
left a comment
There was a problem hiding this comment.
Other than the wholeRange ordering, this looks great.
Thanks for this.
There was a problem hiding this comment.
Is there a reason for computing wholeRange prior to the errorcheck?
There was a problem hiding this comment.
Since we're doing a recovery for the error it doesn't really matter which order is used. I can change it if you really want it but I find it just a matter of style.
There was a problem hiding this comment.
If the work is not necessary for evaluating the error, then it probably makes sense to move it. :-)
There was a problem hiding this comment.
I notice the last set of changes, also had this pattern. So, I guess there is precedent in the codebase :-)
There was a problem hiding this comment.
Yea, there is already precedent, so it's fair to keep it as is.
There was a problem hiding this comment.
If the work is not necessary for evaluating the error, then it probably makes sense to move it. :-)
There was a problem hiding this comment.
We are also including the opt_attributes range as well. When there is an error on the val field, will the error range extend itself to include the attributes? If so, I don't know if that would be desirable because attributes can be on the previous line; would mean the error squiggle would show on whitespace.
There was a problem hiding this comment.
Seems that it will:
// TypeChecker.fs
let TcAndPublishMemberSpec cenv env containerInfo declKind tpenv memb =
match memb with
| SynMemberSig.ValField(_, m) -> error(Error(FSComp.SR.tcFieldValIllegalHere(), m))
....But only in this instance and doesn't seem like a common thing.
There was a problem hiding this comment.
Yes, including attributes to the declaration range is one of the motivating reasons for these changes.
There was a problem hiding this comment.
@TIHan this is how it looks in the previous PR for members:
compared to the current highlighting:

The error of course is that member val definitions aren't allowed in classes without constructors, so underlining the whole member definition is probably quite appropriate.
We could improve the rendering of the squiggle to not display on leading whitespace.
There was a problem hiding this comment.
Same as before, looks like we are going to include attributes range as well since wholeRange is being passed from the rules above.
I would check to make sure an actual error range doesn't look bad when the field has attributes on the previous line.
There was a problem hiding this comment.
The errors usually look OK since in many cases they're not covering the whole range, taking a relevant part like an id instead.
There was a problem hiding this comment.
Looks fine, but see comments.
One thing to note, the other constructs like inherit, interface, new do not include their attributes or visibility ranges. So, the change could be breaking some consistency, but that's ok since I imagine the change is going to be useful. Also, your member declaration PR was merged which basically did the same thing as this, but for members.
I want to make sure we don't fill the screen with red since these ranges are larger now. Also, we should have some tests covering this.
|
@auduchinok apparently we have no test cases for this error path. Could you please add one :-) |
KevinRansom
left a comment
There was a problem hiding this comment.
@auduchinok apparently we have no test cases for this error path. Could you please add one :-)
IIRC it's already been inconsistent in some cases and I'm trying fix it in some places when I have to deal with them. Will be happy to have it more consistent, though. :)
Thanks! Sure, will add it. |
It's fine that we can break some inconsistency now. We probably do want the syntax to include the entire range as it will be useful for tooling. I just want to make sure we are considering the effects of the range change for errors/warnings. It doesn't mean we can't do the range change on the syntax itself, it just means we might want to change the error reporting to not include the entire range. But, that is just my opinion. Others agree that it should be the entire thing. |
|
I think this is the sort of thing we'll only know about if people complain. Since this is effectively a tooling change and not a compiler change, we can always revert it and adjust it based on feedback. |
|
@auduchinok , do you fancy adding the test case, then I can get this merged? Thanks Kevin |
f35deff to
ab68027
Compare
|
@KevinRansom Thanks for the reminder, I've added a test. |
ab68027 to
672f059
Compare
672f059 to
88d0f49
Compare
88d0f49 to
dec1cca
Compare
dec1cca to
7a36ed5
Compare
7a36ed5 to
47df661
Compare
|
It's ready. |
KevinRansom
left a comment
There was a problem hiding this comment.
Thanks for this.
nice work.
|
@TIHan any objections? As per your last comment it appears you're fine with taking this. |
|
@TIHan have your concerns been addressed? I think thi is ready to merge Thanks |
TIHan
left a comment
There was a problem hiding this comment.
Thank you for the tests.
It looks good so far; though, I think later we will probably change the error ranges at some point.
* Fix field declaration ranges * Fix type fields ranges * Add test * Fix more ranges * Update baselines

The same fix as in #7676 but for field declarations.