GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use `is not null` syntax by xtqqczze · Pull Request #13286 · PowerShell/PowerShell

Conversation

@xtqqczze

@xtqqczze xtqqczze commented Jul 27, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

PR Summary

  • -replace '!= null', 'is not null' for C# 9.0.
  • Enable C# 9.0 in xUnit.tests.

PR Context

Follow-up #13277.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: or [ WIP ] to the beginning of the title (the WIP bot will keep its status check at Pending while the prefix is present) and remove the prefix when the PR is ready.
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s):
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • Issue filed:
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
  • Tooling
    • I have considered the user experience from a tooling perspective and don't believe tooling will be impacted.
    • OR
    • I have considered the user experience from a tooling perspective and enumerated concerns in the summary. This may include:
      • Impact on PowerShell Editor Services which is used in the PowerShell extension for VSCode (which runs in a different PS Host).
      • Impact on Completions (both in the console and in editors) - one of PowerShell's most powerful features.
      • Impact on PSScriptAnalyzer (which provides linting & formatting in the editor extensions).
      • Impact on EditorSyntax (which provides syntax highlighting with in VSCode, GitHub, and many other editors).

This change is Reviewable

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ghost ghost assigned Dongbo Wang (daxian-dbw) Jul 27, 2020
@xtqqczze

xtqqczze commented Jul 27, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) I think these changes should wait until we have updated code to use features available in C# 8, such as null operators and pattern matching.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Jul 27, 2020

Copy link
Copy Markdown
Collaborator

The pattern comes from C# 9.0 and is already enabled.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Jul 27, 2020

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) What is mean is I think we should go for "low-hanging fruit" such as using null conditional access from C# 6.0 (RCS1146) etc before making C# 9.0 changes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Jul 27, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) I have started work on related changes in #13286.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Jul 27, 2020

Copy link
Copy Markdown
Contributor Author

Build failures seem to be because preview features not enabled in xUnit.tests.

https://dev.azure.com/powershell/PowerShell/_build/results?buildId=58427&view=logs&j=ce47e5d9-6379-5300-b411-5c447691f9de&t=2718afa2-89c3-5dee-4660-3339d525f0c9&l=37

csharp/test_PSConfiguration.cs(100,47): error CS8652: The feature 'not pattern' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. [/Users/runner/work/1/s/test/xUnit/xUnit.tests.csproj]
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Jul 27, 2020

Copy link
Copy Markdown
Collaborator

You can exclude xUnit files from the PR or enable C# 9.0 in the csproj.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) reviewed Jul 27, 2020
View reviewed changes
Comment thread test/Test.Common.props Resolved

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze
xtqqczze force-pushed the isnotnull branch from 4cdb3bf to 04782d3 Compare July 27, 2020 19:14
@xtqqczze xtqqczze changed the title WIP: Use is not null syntax Use is not null syntax Jul 27, 2020
@xtqqczze

xtqqczze commented Jul 27, 2020

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) If you would like, you can start to review, as we are not isolating C# 9.0 changes. This is already a huge PR so it seems to be the best plan. Any more changes can be in follow-up PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze
xtqqczze marked this pull request as ready for review July 27, 2020 19:45
@xtqqczze
xtqqczze requested review from Steve Lee (SteveL-MSFT), Travis Plunk (TravisEz13), Aditya Patwardhan (adityapatwardhan), Andrew (anmenaga) and Dongbo Wang (daxian-dbw) as code owners July 27, 2020 19:45
@xtqqczze
xtqqczze marked this pull request as draft July 27, 2020 20:40
@xtqqczze
xtqqczze marked this pull request as ready for review July 27, 2020 20:44
iSazonov
Ilya (iSazonov) approved these changes Jul 28, 2020
View reviewed changes
@iSazonov Ilya (iSazonov) added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Jul 28, 2020
@xtqqczze

xtqqczze commented Jul 29, 2020

Copy link
Copy Markdown
Contributor Author

Macos failures look like Test-Connection DNS issues related to #12935.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Jul 30, 2020

Copy link
Copy Markdown
Collaborator

xtqqczze Please rebase to pass CIs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Jul 30, 2020

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) Too many merge conflicts, I will push new commits rather then resolving.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

xtqqczze added 3 commits July 30, 2020 14:38
@xtqqczze
Update Test.Common.props
642a5fe
@xtqqczze
!= null -> is not null
1cedbac
@xtqqczze
Fix CS0037
c20f290
@xtqqczze
xtqqczze force-pushed the isnotnull branch from ce0fb3d to 131bcf7 Compare July 30, 2020 14:03
@xtqqczze

xtqqczze commented Jul 30, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

First rebase on 1f904e4

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze
xtqqczze force-pushed the isnotnull branch from 131bcf7 to c20f290 Compare July 30, 2020 14:09
@xtqqczze

xtqqczze commented Jul 30, 2020

Copy link
Copy Markdown
Contributor Author

Second rebase fixes up.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Jul 30, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

xtqqczze thanks for your efforts in cleaning up the code, but I don't think the is not language feature is for replacing != null. There is nothing wrong using != null. So I don't think we can merge this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Jul 30, 2020

Copy link
Copy Markdown
Contributor Author

Dongbo Wang (@daxian-dbw) This change was actually requested by Ilya (@iSazonov) (#13090 (comment)). Are you against is not generally or just a huge change like this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Jul 30, 2020

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) What do you mean? The pattern "is not null" is for replacement !(x is not null) dotnet/roslyn#42368

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Jul 30, 2020

Copy link
Copy Markdown
Member

Quote from dotnet/roslyn#42368:

Add feature to convert from !(x is null) to x is not null

Ilya (@iSazonov) That conversion makes sense. But most changes in this PR are converting x != null to x is not null, which is not what is suggested. Unlike !(x is null), x != null is explicit and clear, it's conventional and there is no readability issue about it.

Even the !(x is null) is pretty contrived. IMO, is not feature is for cases where we currently use !(x is <a-type-name>).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vexx32

Rain Sallow (/u/ta11ow) (vexx32) commented Jul 30, 2020

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) it's worth noting that == and != operators can both (potentially) be overridden by a type with an implementation that returns unexpected results for a comparison with null; x is not null avoids this possibility.

xtqqczze reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Jul 30, 2020

Copy link
Copy Markdown
Member

Rain Sallow (/u/ta11ow) (@vexx32) Yes, there is such possibility, but I don't think it's practically a problem we need to concern about.

vexx32 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Jul 30, 2020

Copy link
Copy Markdown
Contributor Author

Just to say that if x is a value type, x != null could result in undefined behaviour (see #13285 for examples). x is not null will result in a compiler error instead .

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze xtqqczze mentioned this pull request Jul 30, 2020
Fix comparison of value type object to null #13285
Merged
8 of 14 tasks
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Jul 30, 2020

Copy link
Copy Markdown
Member

xtqqczze I agree that for value types, x != null can actually be considered a bug. I will review #13285 shortly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Jul 30, 2020

Copy link
Copy Markdown
Member

Given that #13277 is reverted, I will close this PR as well. The idea is the same as in #13277 (comment), that we shouldn't force is not null over != null -- neither should be universally preferred; they are appropriate in different scenarios.

xtqqczze reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw Dongbo Wang (daxian-dbw) closed this Jul 30, 2020
@xtqqczze
xtqqczze deleted the isnotnull branch July 30, 2020 23:32
@xtqqczze xtqqczze mentioned this pull request Jul 30, 2020
Use is not syntax and remove unnecessary parentheses #13323
Merged
8 of 14 tasks
@xtqqczze

xtqqczze commented Jul 30, 2020

Copy link
Copy Markdown
Contributor Author

Dongbo Wang (@daxian-dbw) I have made !(x is <a-type-name>) changes in #13323

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Oct 16, 2020

Copy link
Copy Markdown
Collaborator

I think we should re-review this again since .Net team added new Roslyn analyzer to force using new syntax "is null" and "is not".

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Oct 22, 2020

Copy link
Copy Markdown
Contributor Author

I think we should re-review this again since .Net team added new Roslyn analyzer to force using new syntax "is null" and "is not".

Yep, see dotnet/runtime#42692

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@xtqqczze

xtqqczze commented Oct 26, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

We should wait until #13333 and #13338 are merged to avoid conflicts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@iSazonov Ilya (iSazonov) iSazonov approved these changes
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) Awaiting requested review from adityapatwardhan adityapatwardhan is a code owner
@anmenaga Andrew (anmenaga) Awaiting requested review from anmenaga
@daxian-dbw Dongbo Wang (daxian-dbw) Awaiting requested review from daxian-dbw daxian-dbw is a code owner
@SteveL-MSFT Steve Lee (SteveL-MSFT) Awaiting requested review from SteveL-MSFT
@TravisEz13 Travis Plunk (TravisEz13) Awaiting requested review from TravisEz13 TravisEz13 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@daxian-dbw Dongbo Wang (daxian-dbw)

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@xtqqczze @iSazonov @daxian-dbw @vexx32
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.