Correcting false positive inspection match with custom pattern fails

Greetings,


I have a pattern where I have a sequence of `Nullable<T>` instances which I filter via `Where` testing for null, then later use the instance `Value`. R# pegs this as a "Possible InvalidOperationException" since it can't seem to determine that I've already checked for and filtered out `null` earlier in the LINQ method chain.

I've created a custom pattern to test for this:

$e$.Where($p$ => $b$ != null).$m$($q$ => $c$.Value)



which works to match the usages. However, R# continues to flag the $c$ term as a "Possible InvalidOperationException" even though I set the match "Pattern Severity" to be "Do Not Show".

How do I get R# to disregard the $c$ term and quit reporting this false positive?
4 comments
Avatar
Andrey Serebryansky
Comment actions Permalink

Hello
     This is a known problem, but I'm afraid it cannot be solved by creating such pattern. At the moment the only workaround is to rewrite the code and explicitly check your nullable variables for null inside 'if' condition. Thank you!

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0
Comment actions Permalink

Thanks Andrey,

It seems that this kind of expression pattern matching would be generally useful, given especially the nature of LINQ expressions. Is support for this planned? Do you know if there is a YouTrack issue to represent this?

0
Avatar
Andrey Serebryansky
Comment actions Permalink

Hello
     You're welcome to monitor the status of the following request for instance: http://youtrack.jetbrains.com/issue/RSRP-200225
     In order to get notified when this problem gets fixed. Thank you!

Andrey Serebryansky

Senior Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0

Please sign in to leave a comment.