JetBrains / JetBrains/resharper-unity

Suggestion to use "is { }" pattern for null checking is wrong.

Open
#1,986 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
1.2k
Forks
142
PR merge metrics
No merged PRs in 30d

Description

Take this piece of code:

```
private void OnDrawGizmosSelected()
{
Gizmos.DrawSphere(rb.position, 1.0f);
}
```

*Check expression for null* changes it to this which doesn't work for Unity objects:

```
private void OnDrawGizmosSelected()
{
if (rb is { })
Gizmos.DrawSphere(rb.position, 1.0f);
}
```

Instead it should do this:

```
private void OnDrawGizmosSelected()
{
if (rb != null)
Gizmos.DrawSphere(rb.position, 1.0f);
}
```

Now that's even more problematic because nowhere in the options this can be changed.

JetBrains ReSharper 2020.3 Build 203.0.20201211.113035
Unity Support 2020.3.1.132

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.