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

Take advantage of C# 11 #6164

Merged
merged 8 commits into from
Mar 10, 2022
Merged

Conversation

davidwengier
Copy link
Contributor

@davidwengier davidwengier commented Mar 9, 2022

Fixes: My own personal issues.

Commit-by-commit review thoroughly recommended, so you can skip the mechanical change and look at the interesting ones separately. The second commit, with the message that is just "Simplify null checks" is 100% mechanical, and will presumably kill github 😬

This change is 100% mechanical, applying the code fix for the solution, and only contains files that didn't end up with warnings after the fix as applied.
The vsHostWorkspaceServicesProvider parameter was being checked for null despite being nullable, and an optional MEF import.
This was previously validating a nullable parameter, which doesn't make sense, so made the parameter non-nullable, and changed call sites.
@davidwengier

This comment was marked as outdated.

This was null checking a nullable parameter, which doesn't make sense, so made the parameter non-nullable. Callers just suppress so runtime behaviour is unchanged
This was null checking a nullable parameter, which doesn't make sense, so made the parameter non-nullable. Callers just suppress so runtime behaviour is unchanged
@davidwengier davidwengier marked this pull request as ready for review March 9, 2022 23:53
Copy link
Contributor

@NTaylorMullen NTaylorMullen left a comment

Choose a reason for hiding this comment

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

Love it!!

:shipit: !!

Directory.Build.props Show resolved Hide resolved
eng/Versions.props Show resolved Hide resolved
Comment on lines -91 to -94
if (vsHostWorkspaceServicesProvider is null)
{
throw new ArgumentNullException(nameof(vsHostWorkspaceServicesProvider));
}
Copy link
Member

Choose a reason for hiding this comment

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

😕 Why are we removing this line instead of making the argument required?

Copy link
Member

Choose a reason for hiding this comment

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

📝 Note that null checking an optional MEF import is intentional in some cases:
dotnet/roslyn#59047

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm confused.. when you say "make the argument required" do you mean remove the AllowDefault? If so, well because I assume the MEF import sometime isn't satisfied, and if not, well that just seems counter intuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gonna merge this, as with so many changes its a merge conflict waiting to happen. Will follow up if there is any action here.

Copy link
Member

Choose a reason for hiding this comment

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

The desired outcome here is to continue to have [Import(AllowDefault = true)], but also have !! on the parameter. This results in a MEF 2 composition which will not fail to compose for lack of this part, but will throw an exception if anything tries to obtain this part. For example, if the catalog doesn't provide vsHostWorkspaceServicesProvider, it would be perfectly acceptable to obtain Lazy<RazorLanguageServerClient> from the catalog, but you could not access Lazy<RazorLanguageServerClient>.Value without an exception.

Copy link
Member

Choose a reason for hiding this comment

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

➡️ Filed follow-up issue #6165

Copy link
Contributor Author

@davidwengier davidwengier Mar 10, 2022

Choose a reason for hiding this comment

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

Interesting.. and weird :P

Does it change your thinking at all knowing that the code that uses the service later was already defensive against nulls? I took that as a sign that there are legitimate scenarios where the part might not be available (which granted, either isn't true any more, or wasn't working anyway because it would have thrown an exception.. but I imagine there is a non-zero amount of scenarios that aren't working because we throw exceptions)

Copy link
Contributor

@ryanbrandenburg ryanbrandenburg left a comment

Choose a reason for hiding this comment

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

Noice!

@davidwengier davidwengier merged commit 21a30e2 into dotnet:main Mar 10, 2022
@davidwengier davidwengier deleted the NewCSharpHotness branch March 10, 2022 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants