'condition is always true' is false
Hello,
Can someone please explain what ReSharper is doing here?


^ What we have here is a foreach loop in typescript. item becomes the object of each iteration. item is used to flesh out an object which is added to an array called categoryRows. One of the fields of this object is safeguardId. item.ID is assigned to safeguardId. Note that in the first screen shot, there is no check to see if item is null before accessing the property ID from it, whereas in the second screen shot there is.
My question is: why, when there is no null check, does ReSharper think all subsequent null checks below it (where other properties of item are assigned to other fields) are always true? I know for fact they are not. I listened to ReSharper and removed the null checks (thinking that maybe typescript skips any null items in the array of items) only to find that it crashed because item was sometimes null.
I suggest this be logged as a bug not only because the warning that the condition is always true is incorrect but because whether or not having a null check on the assignment to safeguardId should have no bearing on whether subsequent null checks are always true or not.
Please sign in to leave a comment.
Hello!
Thank you for the feedback.
I've filed corresponding issue - https://youtrack.jetbrains.com/issue/RSRP-467693
Please feel free to comment or vote for it.
Thank you.