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

Fix S3900 FN: Conversion operations #7002

Merged
merged 10 commits into from
Mar 29, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ bool NullableStateIsNotKnownForParameter(IParameterSymbol symbol) =>

private static bool IsParameterDereferenced(IOperationWrapperSonar operation) =>
operation.Parent != null
&& operation.Parent.IsAnyKind(
&& (operation.Parent.IsAnyKind(
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition is getting a bit difficult to read.
Maybe it would make sense to build an array of OperationKindEx, to be used in IsAnyKind?

OperationKindEx.Invocation,
OperationKindEx.FieldReference,
OperationKindEx.PropertyReference,
OperationKindEx.EventReference,
OperationKindEx.Await,
OperationKindEx.ArrayElementReference);
OperationKindEx.ArrayElementReference)
|| (operation.Parent.Kind == OperationKindEx.Conversion && IsParameterDereferenced(operation.Parent.ToSonar())));
Copy link
Contributor

Choose a reason for hiding this comment

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

The formatting makes this hard to understand. Try indenting the last line.

Copy link
Contributor

Choose a reason for hiding this comment

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

The || operator should be indented one level further w.r.t. the && operator above (to which is not aligned either, by one char).
I think however, that it would be better to simplify the structure of this logical condition, since you have different logical operators at different levels of nesting.


private sealed class ArgumentDereferenceWalker : SafeCSharpSyntaxWalker
{
Expand Down