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

Use !! in AddParameterCheck refactoring #57934

Merged

Conversation

RikkiGibson
Copy link
Contributor

Related to #36024

@CyrusNajmabadi for review

@RikkiGibson RikkiGibson requested a review from a team as a code owner November 23, 2021 01:06
@@ -5775,6 +5775,28 @@ static object F()
await AssertFormatAsync(expectedCode, code);
}

[Fact]
[Trait(Traits.Feature, Traits.Features.Formatting)]
public async Task SpacingInNullCheckedParameter()
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget to also test/handle the syntax normalize (SyntaxNormalizerTests.cs) which generally needs similar fixing.

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 didn't see a similar test in SyntaxNormalizerTests for the ! operator. Didn't we have to do something similar with that for formatting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't clear to me what needs to be done here.

currentToken.Parent.IsKind(SyntaxKind.Parameter))
{
return CreateAdjustSpacesOperation(0, AdjustSpacesOption.ForceSpacesIfOnSingleLine);
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider also adding a test to SyntacticClassifierTests.cs and SemanticQuickInfoSourceTests.cs. This way, the PR covers all IDE basics (formatting, classifier, quick info, since completion is N/A).

@jcouv jcouv self-assigned this Nov 23, 2021
}";
await new VerifyCS.Test
{
LanguageVersion = LanguageVersion.Preview,
Copy link
Member

Choose a reason for hiding this comment

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

For the cases where the test is the same other than changing language version, consider using a xUnit theory instead of a fact to avoid all the extra duplication.

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Some comments from me, but wait until @CyrusNajmabadi signs off.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Compiler-side (comments-only change) LGTM Thanks (iteration 4)

{
foreach (var parameterNode in parameterNodes)
{
var parameter = (IParameterSymbol)semanticModel.GetRequiredDeclaredSymbol(parameterNode, cancellationToken);
if (index == parameter.Ordinal)
{
return parameter;
return ((TParameterSyntax)parameterNode, parameter);
Copy link
Member

Choose a reason for hiding this comment

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

this worries me. were we blindly casting before?

Copy link
Contributor Author

@RikkiGibson RikkiGibson Nov 30, 2021

Choose a reason for hiding this comment

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

I think we were not casting the items in parameterNodes before this PR.

It appears parameterNodes contains a SeparatedSyntaxList<ParameterNode> which was converted to an IReadOnlyList<SyntaxNode> within SyntaxGenerator.GetParameters.

I would be open to any refactoring/additional helpers which would make this code safer/more maintainable.

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 changed to simply cast the list of parameter nodes which I think will make it more clear what exactly our assumption is.

@RikkiGibson
Copy link
Contributor Author

Could I please get a second review on the relatively small (I think only comments) changes on the @dotnet/roslyn-compiler side?

Copy link
Member

@cston cston left a comment

Choose a reason for hiding this comment

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

Compiler changes LGTM.

/// <summary>
/// True if the compiler will synthesize a null check for this parameter (the parameter is declared in source with a '!' following the parameter name).
/// True if the compiler will synthesize a null check for this parameter (the parameter is declared in source with a '!!' following the parameter name).
Copy link
Member

@Youssef1313 Youssef1313 Dec 3, 2021

Choose a reason for hiding this comment

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

nit: I don't know whether this should be <c>!!</c> or not. This will render differently on docs.microsoft.com.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps it would make sense to have a tracking issue to verify the rendering/appearance of documentation comments, and perform adjustments like the one you've suggested.

{
await new VerifyCS.Test
{
LanguageVersion = LanguageVersion.Preview,
Copy link
Member

Choose a reason for hiding this comment

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

Why is this Preview and not the new CSharpNext? I understand both are equivalent, but CSharpNext should help updating this to CSharp11 when released.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an oversight. Thanks for catching it.

Comment on lines +101 to +104
if (options.LanguageVersion < LanguageVersionExtensions.CSharpNext)
{
return null;
}
Copy link
Member

Choose a reason for hiding this comment

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

I was a bit surprised to see this. My expectation is that we would let the operation proceed without syntax checks and let later diagnostics catch that. Is there any other place where we have syntax based ops that depend on /langVersion?

Copy link
Member

Choose a reason for hiding this comment

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

this is very normal on the IDE side. remember that the user is just saying they want to add a "null check", not that they want to add !!. The IDE normally takes a stance with these types of operations on choosing the most idiomatic form that is legal for the version of the language the user is on.

That way users on C#10 will get the best option they can use, wihle those on 11 will get !!.

If users explicitly write out the C#11 version, then our 'upgrade project' analyzer kicks in and will help them upgrade if they want.

@RikkiGibson RikkiGibson enabled auto-merge (squash) December 7, 2021 22:23
Comment on lines +281 to +282
[InlineData(LanguageVersionExtensions.CSharpNext)]
[InlineData(LanguageVersion.CSharp8)]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[InlineData(LanguageVersionExtensions.CSharpNext)]
[InlineData(LanguageVersion.CSharp8)]
[CombinatorialData]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ends up giving us unexpected diagnostics about use of partial methods in C# 2.

Comment on lines +328 to +329
[InlineData(LanguageVersionExtensions.CSharpNext)]
[InlineData(LanguageVersion.CSharp8)]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
[InlineData(LanguageVersionExtensions.CSharpNext)]
[InlineData(LanguageVersion.CSharp8)]
[CombinatorialData]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants