Skip to content

Conversation

@LLLXXXCCC
Copy link

{
IArrayInitializerOperation arrayInitializerOperation = (IArrayInitializerOperation)operationAnalysisContext.Operation;
if (sourceInfoSymbolMap.IsSourceConstantArrayOfType(arrayInitializerOperation.Parent.Type as IArrayTypeSymbol))
if (sourceInfoSymbolMap.IsSourceConstantArrayOfType(arrayInitializerOperation.GetAncestor<IArrayCreationOperation>(OperationKind.ArrayCreation).Type as IArrayTypeSymbol))

Choose a reason for hiding this comment

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

Can we be even more defensive and handle GetAncestor returning null gracefully by using “?.Type”?


if (this.DataFlowAnalysisContext.SourceInfos.IsSourceConstantArrayOfType(operation.Parent.Type as IArrayTypeSymbol)
IArrayCreationOperation arrayCreationOperation = operation.GetAncestor<IArrayCreationOperation>(OperationKind.ArrayCreation);
IArrayTypeSymbol arrayTypeSymbol = arrayCreationOperation.Type as IArrayTypeSymbol;

Choose a reason for hiding this comment

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

Same here. I would handle null value return by GetAncestor and also null check before invoking IsSourceConstantArrayOfType (unless that method handles null input).

@LLLXXXCCC LLLXXXCCC merged commit a1a198d into dotnet:master Jul 29, 2019
}

[Fact]
public void Test_HardcodedIn2DByteArray_CreateEncryptor_Diagnostic()
Copy link

Choose a reason for hiding this comment

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

Test_HardcodedIn2DByteArray_CreateEncryptor_Diagnostic [](start = 20, length = 54)

It'd be good to add a test for a jagged array (like byte[][]) also.

Is there a test case that covers the assert from #2708?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants