dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.87k stars 4.01k forks source link

Is it possible to have IArgumentOperation.Parameter null? #41907

Open Evangelink opened 4 years ago

Evangelink commented 4 years ago

Hi,

The IArgumentOperation operation has a Parameter property, are we ensured that the result is never null? If not could you please give some info toward when this could be null?

I'd like to increase the coverage of one analyzer, so I either need to remove the null check or add a unit-test.

See https://github.com/dotnet/roslyn-analyzers/issues/3115

Thank you

jinujoseph commented 4 years ago

cc @mavasani

mavasani commented 4 years ago

I believe it cannot be null. Tagging @333fred @AlekseyTs to confirm.

333fred commented 4 years ago

I believe that is correct. @jaredpar, this an example of where annotating IOperation would be useful.

Evangelink commented 4 years ago

Thank you all for the answers!

@mavasani I will remove the null checks on the 2 linked ticket in roslyn-analyzers if that's ok for you.

@333fred Is there something I could help with?

333fred commented 4 years ago

@Evangelink if you wanted to take a stab at annotating IOperation interfaces, you'd be more than welcome to do so. We have a general doc on annotating here: https://github.com/dotnet/roslyn/blob/master/docs/contributing/Nullable%20Annotations.md. The basic strategy for IOperation that I've come up with is to start with the leaf nodes, annotate those, and then work up the tree. Annotating this is basically an investigation into the C# and VB behavior of the BoundTree, seeing what elements correspond to what IOperation elements, and annotating appropriately. For example, there are fields that might never be null in C#, but might be null in VB, and vice versa.

Evangelink commented 4 years ago

@333fred Let me know if I got things right. Let's say I want to ensure that the Parameter property of IArgumentOperation is never null. I look at all the types implementing the interface, then to all path leading to the property being set (for C# and vbnet) and if they are all not null then that's ok to mark the property as not null? The interface being auto-generated, how shall I mark it as non-null?

333fred commented 4 years ago

@Evangelink it would require changing the generator to understand nullability. To be frank, if that sounds like to much work I understand, it's why we haven't done it yet. We'll get to it in the next few months.

Evangelink commented 4 years ago

I totally get it 😄😄😄

Honestly, I'd be happy to help but I am afraid to have you spend a lot of time answering my questions so I don't know if this would end up being advantageous for you.