JetBrains / JetBrains/resharper-unity

"Comparison to null is expensive" warning can be misleading

Open
#2,365 3 comments 5 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
1.2k
Forks
142
PR merge metrics
No merged PRs in 30d

Description

The warning, [Avoid null comparisons against UnityEngine.Object subclasses](https://github.com/JetBrains/resharper-unity/wiki/Avoid-null-comparisons-against-UnityEngine.Object-subclasses) shows for this code:
```
if (obj != null) DoSomething();
```
But not showing for this code:
```
if (obj) DoSomething();
```
Since bool cast operator of `UnityEngine.Object` does the same thing as comparing to `null`, the warning should be shown as same. Otherwise, it can mislead users to use bool cast instead, which is worse practice as it is less explicit.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.