JetBrains / JetBrains/resharper-unity
"Comparison to null is expensive" warning can be misleading
Open
- 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
Assessment
This issue has not been assessed yet.