-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Handle nullability attributes in param-nullchecking #59393
Changes from 4 commits
48e5ecb
07e63fc
3618a98
aa6f565
0d8c58d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -809,12 +809,16 @@ internal static void ReportParameterNullCheckingErrors(DiagnosticBag diagnostics | |
{ | ||
diagnostics.Add(ErrorCode.ERR_DiscardCannotBeNullChecked, location); | ||
} | ||
if (parameter.TypeWithAnnotations.NullableAnnotation.IsAnnotated() | ||
|| parameter.Type.IsNullableTypeOrTypeParameter()) | ||
|
||
var annotations = parameter.FlowAnalysisAnnotations; | ||
if ((annotations & FlowAnalysisAnnotations.NotNull) == 0 | ||
&& !NullableWalker.GetParameterState(parameter.TypeWithAnnotations, annotations, applyParameterNullCheck: false).IsNotNull | ||
&& (!parameter.Type.IsTypeParameter() || parameter.Type.IsNullableTypeOrTypeParameter() || parameter.TypeWithAnnotations.NullableAnnotation.IsAnnotated() || (annotations & FlowAnalysisAnnotations.AllowNull) != 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally, if it's possible for a parameter of a type parameter type to be non-nullable after substitution, we want to avoid giving the warning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From offline chat: |
||
{ | ||
diagnostics.Add(ErrorCode.WRN_NullCheckingOnNullableType, location, parameter); | ||
} | ||
else if (parameter.Type.IsValueType && !parameter.Type.IsPointerOrFunctionPointer()) | ||
|
||
if (parameter.Type.IsNonNullableValueType() && !parameter.Type.IsPointerOrFunctionPointer()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to dislike |
||
{ | ||
diagnostics.Add(ErrorCode.ERR_NonNullableValueTypeIsNullChecked, location, parameter); | ||
} | ||
|
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 simplifying the double-negation:
&& NullableWalker.GetParameterState(....).MayBeNull
Correction: should use the extension method
MayBeNull()
. Somehow,MaybeNull
property andMayBeNull()
extension method diverged for the maybe-default case :-/