Skip to content

Fix more declaration ranges#7774

Merged
KevinRansom merged 5 commits into
dotnet:masterfrom
auduchinok:fieldRanges
Mar 2, 2020
Merged

Fix more declaration ranges#7774
KevinRansom merged 5 commits into
dotnet:masterfrom
auduchinok:fieldRanges

Conversation

@auduchinok

Copy link
Copy Markdown
Member

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

@auduchinok

Copy link
Copy Markdown
Member Author

This is ready.

@cartermp cartermp requested review from TIHan and dsyme October 29, 2019 15:13

@KevinRansom KevinRansom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the wholeRange ordering, this looks great.

Thanks for this.

Comment thread src/fsharp/pars.fsy Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for computing wholeRange prior to the errorcheck?

@auduchinok auduchinok Oct 30, 2019

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the work is not necessary for evaluating the error, then it probably makes sense to move it. :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice the last set of changes, also had this pattern. So, I guess there is precedent in the codebase :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, there is already precedent, so it's fair to keep it as is.

Comment thread src/fsharp/pars.fsy Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the work is not necessary for evaluating the error, then it probably makes sense to move it. :-)

Comment thread src/fsharp/pars.fsy Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@TIHan TIHan Oct 31, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, including attributes to the declaration range is one of the motivating reasons for these changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TIHan this is how it looks in the previous PR for members:

image

compared to the current highlighting:
image

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.

Comment thread src/fsharp/pars.fsy Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The errors usually look OK since in many cases they're not covering the whole range, taking a relevant part like an id instead.

@TIHan TIHan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@KevinRansom

Copy link
Copy Markdown
Contributor

@auduchinok apparently we have no test cases for this error path. Could you please add one :-)

@KevinRansom KevinRansom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@auduchinok apparently we have no test cases for this error path. Could you please add one :-)

@auduchinok

auduchinok commented Oct 31, 2019

Copy link
Copy Markdown
Member Author

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.

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. :)

@auduchinok apparently we have no test cases for this error path. Could you please add one :-)

Thanks! Sure, will add it.

@TIHan

TIHan commented Oct 31, 2019

Copy link
Copy Markdown
Contributor

Will be happy to have it more consistent, though.

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.

@cartermp

Copy link
Copy Markdown
Contributor

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.

@KevinRansom

KevinRansom commented Jan 21, 2020

Copy link
Copy Markdown
Contributor

@auduchinok , do you fancy adding the test case, then I can get this merged?

Thanks

Kevin

@auduchinok auduchinok force-pushed the fieldRanges branch 2 times, most recently from f35deff to ab68027 Compare January 23, 2020 17:07
@auduchinok

Copy link
Copy Markdown
Member Author

@KevinRansom Thanks for the reminder, I've added a test.

@auduchinok auduchinok changed the title Fix field declaration ranges Fix more declaration ranges Jan 27, 2020
@auduchinok auduchinok closed this Feb 27, 2020
@auduchinok auduchinok reopened this Feb 27, 2020
@auduchinok

Copy link
Copy Markdown
Member Author

It's ready.

@KevinRansom KevinRansom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

nice work.

@cartermp

Copy link
Copy Markdown
Contributor

@TIHan any objections? As per your last comment it appears you're fine with taking this.

@KevinRansom

Copy link
Copy Markdown
Contributor

@TIHan have your concerns been addressed? I think thi is ready to merge

Thanks
Kevin

@TIHan TIHan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the tests.

It looks good so far; though, I think later we will probably change the error ranges at some point.

@KevinRansom KevinRansom merged commit 79837ec into dotnet:master Mar 2, 2020
@auduchinok auduchinok deleted the fieldRanges branch March 2, 2020 21:15
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
* Fix field declaration ranges

* Fix type fields ranges

* Add test

* Fix more ranges

* Update baselines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants