Enable and refactor to fix IDE0031 Use null propagation#7902
Enable and refactor to fix IDE0031 Use null propagation#7902RussKie merged 1 commit intodotnet:mainfrom
Conversation
|
IDE0031 seems to not take into account |
|
Thank you. Just to confirm, are there any manual changes or all changes are done by the auto fixers? |
|
The build is failing. |
The analyzer is broken and doesn't take into account |
|
@RussKie could we remove the |
I just checked on sharplab.io, release builds remove the call to |
|
No, we can't simply remove diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
index 4d3f98914..6e4d8a2c5 100644
--- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
+++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs
@@ -10915,6 +10915,7 @@ namespace System.Windows.Forms
#if DEBUG
int suspendCount = -44371; // Arbitrary negative prime to surface bugs.
#endif
+#pragma warning disable IDE0031 // Use null propagation
if (ParentInternal is not null)
{
#if DEBUG
@@ -10922,6 +10923,7 @@ namespace System.Windows.Forms
#endif
ParentInternal.SuspendLayout();
}
+#pragma warning restore IDE0031 // Use null propagation
try
{ |
|
In cases where an |
|
Yes, but you may find that there are variables that are defined in DEBUG only, e.g., in |
Thanks. I will add the supressions and remove any |
f8d1444 to
a0a4c80
Compare
|
If I may ask you to consider adding fixup commits or just additional commits to ease the reviews whenever the changeset are this large. F-push makes it very hard to appreciate what changed. |
Not a problem! I will do so in the future, I wasn't sure if you did squash merges and didn't want to pollute the main branch. |
|
Thank you for the consideration 👍 |
Used the build in Analyzer's code fix.
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0031
The analyzer currently is broken and doesn't take into account
#if DEBUGstatements.Issue: dotnet/roslyn#65880
Related: #7887
Microsoft Reviewers: Open in CodeFlow