Skip to content

Conversation

@RikkiGibson
Copy link
Member

Related to #36024

@ghost ghost added the Area-Compilers label Oct 26, 2021
@RikkiGibson RikkiGibson marked this pull request as ready for review October 26, 2021 20:40
@RikkiGibson RikkiGibson requested a review from a team as a code owner October 26, 2021 20:40
@RikkiGibson RikkiGibson requested review from chsienki and cston October 26, 2021 20:40
// void M0(string name !!=null) { }
Diagnostic(ErrorCode.WRN_NullCheckedHasDefaultNull, "name").WithArguments("name").WithLocation(5, 20),
// (6,20): warning CS8993: Parameter 'name' is null-checked but is null by default.
// void M1(string name! !=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'm surprised that we're issuing a warning for this. Presumably we're error recovering the !! so now emitting the warning too, but it seems... odd to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I didn't look extremely deeply into why--may relate to exactly where I moved the calls ParameterHelpers.AddNullCheckErrorsToParameter. Basically if expediency makes these warnings go away, or makes them stick around in the presence of syntax errors, I'm fine either way.

{
[CompilerTrait(CompilerFeature.IOperation)]
public class IOperationTests : SemanticModelTestBase
public partial class IOperationTests : SemanticModelTestBase
Copy link
Contributor

Choose a reason for hiding this comment

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

partial

Is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like the IOperation tests added in the feature were not updated to match the new convention. I was able to remove this partial modifier after making the new tests use a conventional name.

{
var nullableHasValue = ((IMethodSymbol)_compilation.CommonGetSpecialTypeMember(SpecialMember.System_Nullable_T_get_HasValue))?.Construct(parameter.Type);
if (nullableHasValue is null)
// PROTOTYPE(param-nullchecking): is there a better way to get the HasValue symbol here?
Copy link
Contributor

Choose a reason for hiding this comment

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

get the HasValue symbol

Perhaps _compilation.GetSpecialTypeMember(SpecialType.System_Nullable_T_get_HasValue).Construct(parameter.Type).

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't construct the HasValue member, we have to construct Nullable<T> and then somehow get HasValue off of it. Normally in the compiler we would construct the Nullable<{parameter.Type}>, get the original definition of Nullable<T>.HasValue, then use the AsMemberOfType helper to get the construction of HasValue within the constructed Nullable<{parameter.Type}>.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was actually a bit surprised by the original code. It seems like it probably never worked.

namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
public partial class IOperationTests : SemanticModelTestBase
public partial class IOperationTests_NullCheckedParameters : SemanticModelTestBase
Copy link
Contributor

Choose a reason for hiding this comment

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

partial

Is partial necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

}

[Fact]
[Fact(Skip = "PROTOTYPE(param-nullchecking): MakeMemberMissing doesn't work as expected with our method of obtaining Nullable<T>.HasValue in this scenario")]
Copy link
Contributor

@cston cston Oct 27, 2021

Choose a reason for hiding this comment

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

PROTOTYPE(param-nullchecking): MakeMemberMissing

Consider compiling with a custom corlib with a minimal set of types.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will address in a later PR.


ImmutableArray<string> names = default;
ImmutableArray<RefKind> refKinds = default;
ImmutableArray<bool> nullCheckedOpt = default;
Copy link
Member

Choose a reason for hiding this comment

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

Consider using a BitVector for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems reasonable. Will look at this in a follow-up PR.

@RikkiGibson RikkiGibson merged commit 6ba3dea into dotnet:features/param-nullchecking Nov 1, 2021
@RikkiGibson RikkiGibson deleted the pnc-fix-build branch November 1, 2021 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants