-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix param-nullchecking build/test failures #57375
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
Fix param-nullchecking build/test failures #57375
Conversation
| // 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) { } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs
Outdated
Show resolved
Hide resolved
| { | ||
| [CompilerTrait(CompilerFeature.IOperation)] | ||
| public class IOperationTests : SemanticModelTestBase | ||
| public partial class IOperationTests : SemanticModelTestBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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}>.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Related to #36024