Make extracted parameters non-nullable when possible. #76386
Merged
CyrusNajmabadi merged 6 commits intodotnet:mainfrom Dec 13, 2024
Merged
Make extracted parameters non-nullable when possible. #76386CyrusNajmabadi merged 6 commits intodotnet:mainfrom
CyrusNajmabadi merged 6 commits intodotnet:mainfrom
Conversation
Contributor
Author
|
@JoeRobich @ToddGrun @akhera99 this is ready for review. |
DustinCampbell
approved these changes
Dec 13, 2024
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Security; |
Member
There was a problem hiding this comment.
Was this intentional? It doesn't look to me like anything uses something from System.Security.
CyrusNajmabadi
commented
Dec 13, 2024
3 tasks
JoeRobich
approved these changes
Dec 13, 2024
| {|CS8602:c|}.ToString(); | ||
| c = null; | ||
| c?.ToString(); | ||
| return c; |
Member
There was a problem hiding this comment.
Why return c if the extracted selection contains the last reference to it?
Contributor
Author
There was a problem hiding this comment.
Unclear :-). I'll have to debug through to see what's going on (note, this is unrelated to this pr).
This was referenced Dec 14, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #61555
Followup to #76383. That needs to go in first.
Note: this is not a generally solvable issue. Fundamentally a parameter cannot represent the same sort of 'flow' state that a local variable. It is either declared as 'nullable' and the flow-in state is 'maybe null' (which may not match the flow in state of the calling code), or it is declared as 'non nullable', but then would warn on null assignments taht would be allowed in the caller.
I too the position that if the value being passed is known to be non-null at all points within the selection, the it should be treated as a non-nullable parameter. If it ever couldbe null, then the parameter remains nullable.