Skip to content

all appearances of "== null" are replaced with "is null" and all appe… - #3469

Closed
sashatankov wants to merge 2 commits into
dotnet:masterfrom
sashatankov:sasha-tankov2
Closed

sashatankov wants to merge 2 commits into
dotnet:masterfrom
sashatankov:sasha-tankov2

Conversation

@sashatankov

@sashatankov sashatankov commented Jun 18, 2020 •

Copy link
Copy Markdown

…arances of "!= null" are replaced with "is not null"

Fixes #

Proposed changes

Customer Impact

Regression?

  • Yes / No

Risk

Screenshots

Before

After

Test methodology

Accessibility testing

Test environment(s)

Microsoft Reviewers: Open in CodeFlow

…arances of "!= null" are replaced with "is not null"
@sashatankov
sashatankov requested a review from a team as a code owner June 18, 2020 12:56
@ghost ghost assigned sashatankov Jun 18, 2020
@dnfadmin

dnfadmin commented Jun 18, 2020 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

}

Debug.Fail("No conversion from " + value == null ? "null" : value.GetType().FullName + " to byte[]");
Debug.Fail("No conversion from " + value is null ? "null" : value.GetType().FullName + " to byte[]");

@weltkante weltkante Jun 18, 2020 •

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.

Anyone know if this change (from == to is) is safe in terms of operator precedence? Or are there edge cases which needs adding braces?

(Not speaking of this particular instance, which is probably ok, but in general terms)

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.

My understanding it is the same operation, just safer.
@jaredpar can you confirm?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TLDR: This is a safe change. The is and == operator have virtually the same precedence so the only realistic change here is moving from a custom == operator to a direct null or non-null check (which is the intent of this PR).

Messy Details

The is operator does have higher precedence than == which means in certain pathological cases this could alter the evaluation order. At the same time is and ==, as well as all the relational operators, are directly next to each other in the precedence table so you'd need a decently pathological to see this occur. Essentially something in the form of a == b == null where you change the second == to is and you have some operators defined over bool.

This is a working example of the type of code you'd need to see this in action. Changing the second == to is will change the code from producing a warning to binding to the custom equality operator.

Again though that is pretty out there. It's not something I'd really focus on for a change like this. I included it only for completeness.

finally
{
if (pipeClient != null)
if (pipeClient is not null)

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.

This is C#9 feature, which hasn't been released yet. I don't think this will work prior to VS 16.7.
So let's concentrate on == null -> is null only, until C#9 is shipped.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ok, so I change only the "is not null" appearances to "!=null". see my last commit

@ghost ghost added the waiting-author-feedback The team requires more information from the author label Jun 19, 2020
@ghost ghost removed the waiting-author-feedback The team requires more information from the author label Jun 19, 2020

@RussKie RussKie 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.

I'm about 10-15% in...


/// <summary>
/// Adds a Node with given label and value to the parent, provided the parent is not null;
/// Adds a Node with given label and value to the parent, provided the parent != null;

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 shouldn't change comments


/// <summary>
/// Creates an instance of the specified type. The default implementation will create the object. If the object implements IComponent and only requires an empty or IContainer style constructor, this will search for IDesignerHost and create through the host. Otherwise it will use reflection. If addToContainer is true, this will add to the container using this class's Conainer property, using the name provided if it is not null.
/// Creates an instance of the specified type. The default implementation will create the object. If the object implements IComponent and only requires an empty or IContainer style constructor, this will search for IDesignerHost and create through the host. Otherwise it will use reflection. If addToContainer is true, this will add to the container using this class's Conainer property, using the name provided if it != null.

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.

ditto

@RussKie

RussKie commented Jun 24, 2020

Copy link
Copy Markdown
Contributor

Please complete filling the PR description.

@RussKie

RussKie commented Jun 24, 2020

Copy link
Copy Markdown
Contributor

There are too may files changed, this will take too long to review.
In the original issue I asked to break changes per project to make them reviewable (500+ files isn't).

Please send separate PRs for each project.
I've fully reviewed System.Windows.Forms.Primitives and it can be merged quickly. I'm probably 30% through reviewing the System.Windows.Forms.Design, and less for System.Windows.Forms.

@RussKie RussKie added the waiting-author-feedback The team requires more information from the author label Jun 26, 2020
@RussKie
RussKie marked this pull request as draft June 26, 2020 11:19
@RussKie RussKie mentioned this pull request Jul 30, 2020
@ghost ghost added the draft draft PR label Sep 11, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

draft draft PR waiting-author-feedback The team requires more information from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants