Incorrect "Expression is always false" suggestion in 5.1.1707

The following code produce an incorrect "Expression is always false" suggestion in R# 5.1.1707.19 on the "if (obj == null)" line.

    struct Test
    {
        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            return base.Equals(obj);
        }
    }

This is incorrect, because even though the object itself is a struct there is nothing stopping "obj" from being null. Another symptom of the same problem is that this line:

new Test().Equals(null);

reports a "Possible null assignment to entity marked with 'NotNull' attribute" warning.

I think the meaning of the [NotNull] attribute has blurred a bit between "shouldn't be null" and "couldn't be null" here. If, as I understand, it means "shouldn't be null" then R# should not use it for the "expression is always true/false" warnings.

4 comments
Comment actions Permalink

Hello evgeny0,

This should be fixed in the latest nightly build of ReSharper 5.1. Thank you!

Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

The following code produce an incorrect "Expression is always false"
suggestion in R# 5.1.1707.19 on the "if (obj == null)" line.

struct Test
{
public override bool Equals(object obj)
{
if (obj == null)
return false;
return base.Equals(obj);
}
}
This is incorrect, because even though the object itself is a struct
there is nothing stopping "obj" from being null. Another symptom of
the same problem is that this line:

new Test().Equals(null);

reports a "Possible null assignment to entity marked with 'NotNull'
attribute" warning.

I think the meaning of the attribute has blurred a bit
between "shouldn't be null" and "couldn't be null" here. If, as I
understand, it means "shouldn't be null" then R# should not use it for
the "expression is always true/false" warnings.

---
Original message URL:
http://www.jetbrains.net/devnet/message/5265795#5265795



0
Comment actions Permalink

It still happens in build 1713.5.

0
Comment actions Permalink

Hello,

I've created a bug-report in our tracker: http://youtrack.jetbrains.net/issue/RSRP-183294.
Thank you!

Andrey Serebryansky
Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

It still happens in build 1713.5.

---
Original message URL:
http://devnet.jetbrains.net/message/5265933#5265933



0
Comment actions Permalink

Thank you, confirmed fixed in 5.1.1714.

0

Please sign in to leave a comment.