Skip to content
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

AddExplicitReturnType refactoring #16077

Merged
merged 63 commits into from
Dec 19, 2023

Conversation

SebastianAtWork
Copy link
Contributor

…and resource file entry

See Issue #15562 for Discussion

@psfinaki

@SebastianAtWork
Copy link
Contributor Author

@SebastianAtWork please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), and conveys certain license rights to the .NET Foundation ( “.NET Foundation” ) for Your contributions to .NET Foundation open source projects. This Agreement is effective as of the latest signature date below.

1. Definitions.

“Code” means the computer software code, whether in human-readable or machine-executable form, that is delivered by You to .NET Foundation under this Agreement.

“Project” means any of the projects owned or managed by .NET Foundation and offered under a license approved by the Open Source Initiative (www.opensource.org).

“Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any Project, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of discussing and improving that Project, but excluding communication that is conspicuously marked or otherwise designated in writing by You as “Not a Submission.”

“Submission” means the Code and any other copyrightable material Submitted by You, including any associated comments and documentation.

2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any Project. This Agreement covers any and all Submissions that You, now or in the future (except as described in Section 4 below), Submit to any Project.

3. Originality of Work. You represent that each of Your Submissions is entirely Your original work. Should You wish to Submit materials that are not Your original work, You may Submit them separately to the Project if You (a) retain all copyright and license information that was in the materials as you received them, (b) in the description accompanying your Submission, include the phrase "Submission containing materials of a third party:" followed by the names of the third party and any licenses or other restrictions of which You are aware, and (c) follow any other instructions in the Project's written guidelines concerning Submissions.

4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your Submission is made in the course of Your work for an employer or Your employer has intellectual property rights in Your Submission by contract or applicable law, You must secure permission from Your employer to make the Submission before signing this Agreement. In that case, the term “You” in this Agreement will refer to You and the employer collectively. If You change employers in the future and desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement and secure permission from the new employer before Submitting those Submissions.

5. Licenses.

a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly or indirectly from .NET Foundation, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third parties.

b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or indirectly from .NET Foundation, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under Your patent claims that are necessarily infringed by the Submission or the combination of the Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and import or otherwise dispose of the Submission alone or with the Project.

c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are granted by implication, exhaustion, estoppel or otherwise.

6. Representations and Warranties. You represent that You are legally entitled to grant the above licenses. You represent that each of Your Submissions is entirely Your original work (except as You may have disclosed under Section 3 ). You represent that You have secured permission from Your employer to make the Submission in cases where Your Submission is made in the course of Your work for Your employer or Your employer has intellectual property rights in Your Submission by contract or applicable law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You have the necessary authority to bind the listed employer to the obligations contained in this Agreement. You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES EXPRESSLY STATED IN SECTIONS 3, 4, AND 6 , THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.

7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or circumstances of which You later become aware that would make Your representations in this Agreement inaccurate in any respect.

8. Information about Submissions. You agree that contributions to Projects and information about contributions may be maintained indefinitely and disclosed publicly, including Your name and other information that You submit with Your Submission.

9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County, Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all defenses of lack of personal jurisdiction and forum non-conveniens.

10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and supersedes any and all prior agreements, understandings or communications, written or oral, between the parties relating to the subject matter hereof. This Agreement may be assigned by .NET Foundation.

.NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1.

@dotnet-policy-service agree

@psfinaki
Copy link
Member

psfinaki commented Oct 5, 2023

@SebastianAtWork that's a great start!

Here are a few quick tips for you:

  1. You'll need to run the full build to get the localized resources generated. They will be untranslated for now, that's fine.
  2. Generally, let's make the CI green and then probably refactor the refactoring a bit (pun intended)
  3. We'd appreciate if at some point you add a demo for the new functionality in the PR description (Snipping tool is enough for that) - it's useful for historical reasons

And special thanks for testing efforts!

@SebastianAtWork SebastianAtWork force-pushed the features/codefix-return-type branch from 9983cbc to 95ef481 Compare October 19, 2023 12:16
@SebastianAtWork SebastianAtWork force-pushed the features/codefix-return-type branch 2 times, most recently from 407572f to 92ee24e Compare October 30, 2023 09:37
@SebastianAtWork
Copy link
Contributor Author

@psfinaki Im currently getting a build error after updating my branch : E:\Repos\fsharp\src\Compiler\Utilities\Cancellable.fs(12,5): error FS0902: For F#7 and lower, static value definitions
may only be used in types with a primary constructor ('type X(args) = ...'). To enable them in all other types, use lan
guage version 'preview'. [E:\Repos\fsharp\src\Compiler\FSharp.Compiler.Service.fsproj::TargetFramework=netstandard2.0]
I tried deleting the temporary vs files and restore and then build. Same error. Should I set the language preview tag in csproj ? Anyone else getting this error?

@psfinaki
Copy link
Member

@SebastianAtWork hmm I will check out your branch tomorrow and see if I am getting the same error, stay tuned.

@psfinaki
Copy link
Member

@SebastianAtWork so I managed to reproduce the error in the Cancellable file but that usually happens due to outdated versions of proto compiler. TLDR try git clean -dfx -e .vs and then build. Solved it for me at least :)

@SebastianAtWork SebastianAtWork force-pushed the features/codefix-return-type branch 2 times, most recently from 1065f22 to d45ca33 Compare November 7, 2023 09:47
@SebastianAtWork SebastianAtWork force-pushed the features/codefix-return-type branch from 6118cd5 to 69f3e11 Compare November 13, 2023 10:14
@SebastianAtWork
Copy link
Contributor Author

@psfinaki Sorry for the delay. I fixed your remarks and some refactorings. Should I add another Test case for when there are multiple documents in a project and one document infers a type from a previous document? Any other test cases I should add?
And can I change this draft to a full PR?

@psfinaki psfinaki marked this pull request as ready for review November 13, 2023 20:57
@psfinaki psfinaki requested a review from a team as a code owner November 13, 2023 20:57
Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

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

Good stuff. Left a few notes, definitely ready to review.

@psfinaki
Copy link
Member

Should I add another Test case for when there are multiple documents in a project and one document infers a type from a previous document?

That would be helpful. At least to see how complicated is to have such a test.

@psfinaki psfinaki changed the title First Draft for AddExplicitReturnType (#15562) with exploration test … AddExplicitReturnType refactoring Nov 13, 2023
@SebastianAtWork SebastianAtWork force-pushed the features/codefix-return-type branch from 38a479a to 6e83b22 Compare November 14, 2023 11:16
@SebastianAtWork SebastianAtWork force-pushed the features/codefix-return-type branch from 1814cc6 to aa88e55 Compare November 20, 2023 11:43
@psfinaki
Copy link
Member

psfinaki commented Dec 7, 2023

@SebastianAtWork awesome, so just then please add them, take your time and no rush!

…peTests.fs

- In AddExplicitReturnType.fs:
  - Replaced the codeActionFunc with a cancellableTask to handle cancellation tokens.
  - Updated the codeActionFunc to use the new cancellableTask and getChangedText functions.

- In AddExplicitReturnTypeTests.fs:
  - Added tests for binding another function and binding linq function without crashing.
  - Updated the expectedCode for these tests to include explicit return types.
@SebastianAtWork
Copy link
Contributor Author

@psfinaki I added the 2 tests that pass and produce a compilable return type. I this correct or should it produce Unit->System.DateTime?

@psfinaki
Copy link
Member

@SebastianAtWork this is correct. We need return types, not the full signatures. Good job :)

@psfinaki
Copy link
Member

Will take a look at this tomorrow, but seems very promising - thanks for the updates!

Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

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

Niiice! No major concerns anymore :)

I would just like to add a few more tests and remove the word explicit. Otherwise good to go IMO.

The code changes simplify the logic in the AddExplicitReturnType module. The changes remove unnecessary conditions and improve readability.
- Added a test case to ensure that the refactor correctly infers the return type of the `sum` function when it is defined on the next line.
- Removed an unused import in the `RefactorTestFramework.fs` file.
refactor: Add explicit return type to sum function
@SebastianAtWork
Copy link
Contributor Author

Niiice! No major concerns anymore :)

I would just like to add a few more tests and remove the word explicit. Otherwise good to go IMO.

Just to understand, Why remove the explicit? Its also called AddExplicitTypeToParameter

@psfinaki
Copy link
Member

Niiice! No major concerns anymore :)
I would just like to add a few more tests and remove the word explicit. Otherwise good to go IMO.

Just to understand, Why remove the explicit? Its also called AddExplicitTypeToParameter

Yeah the refactoring is called like that - but the string is "Add type annotation" (as opposed to "add explicit type annotation") - so just to align with that one :)

The commit updates the return type annotation in multiple localization files.
- Renamed the file `AddExplicitReturnType.fs` to `AddReturnType.fs`.
- Updated references to the renamed file in other files.
- Updated test file names and references accordingly.
@SebastianAtWork
Copy link
Contributor Author

@psfinaki Like this ? :) Done

@psfinaki
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@psfinaki
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@psfinaki
Copy link
Member

@dotnet/fsharp-team-msft please review, this is all green and resolved.

@T-Gro T-Gro merged commit 75ff9a5 into dotnet:main Dec 19, 2023
26 checks passed
@psfinaki
Copy link
Member

Thanks for your contribution @SebastianAtWork. I am thinking now that once this gets to the VS preview, I might write a blog post about refactorings in VS where I could also mention this one and the new testing framework :)

OwnageIsMagic added a commit to OwnageIsMagic/fsharp that referenced this pull request Dec 21, 2023
* upstream/main: (166 commits)
  typo in foldBack summary (dotnet#16453)
  Fix for dotnet#83 (improve constraint error message) (dotnet#16304)
  Name resolution: resolve interfaces in expressions (dotnet#15660)
  AddExplicitReturnType refactoring (dotnet#16077)
  Disabling 2 tests: running for too long, causing CI timeouts
  Improve value restriction error message dotnet#1103 (dotnet#15877)
  Parens: Keep parens for non-identical infix operator pairs with same precedence (dotnet#16372)
  More release note entries (dotnet#16438)
  Using Ordinal is both faster and more correct as our intent is to do … (dotnet#16439)
  merge (dotnet#16427)
  Optimize empty string compares (dotnet#16435)
  Checker: recover on unresolved type in 'inherit' member (dotnet#16429)
  Release notes proposal (dotnet#16377)
  [main] Update dependencies from dotnet/source-build-reference-packages (dotnet#16411)
  Allow usage of [<TailCall>] with older FSharp.Core package versions (dotnet#16373)
  Parser: recover on unfinished 'as' patterns (dotnet#16404)
  Parens: Keep parens in method calls in dot-lambdas (dotnet#16395)
  Checker: check unfinished obj expression inside computations (dotnet#16413)
  Added default dotnet-tools + additional tasks to launch them (dotnet#16409)
  make `remarks` and `returns` visible in quick info (dotnet#16417)
  ...
@SebastianAtWork
Copy link
Contributor Author

Thanks for your contribution @SebastianAtWork. I am thinking now that once this gets to the VS preview, I might write a blog post about refactorings in VS where I could also mention this one and the new testing framework :)

Thanks for helping :) Good Idea yes. On which blog?

@psfinaki
Copy link
Member

On Visual Studio .NET blog, here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants