Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible System.NullReferenceException warning if checking for UnityEngine.Object #1799

Closed
ManuelRauber opened this issue Aug 17, 2020 · 1 comment
Milestone

Comments

@ManuelRauber
Copy link
Contributor

Hi,

if you check a UnityEngine.Object to be null or not, you simply can do the following:

private void Update() {
   if (!someGameObject) {
    // is null
    return;
  }

  // is not null here
  someGameObject.DoSomething(); // Possible System.NullReferenceException
}

In the last line Rider still suggests that someGameObject could be null, which I think is not correct.
That line of code should not be reachable due to the return statement in the if-branch, when someGameObject is null.

@citizenmatt
Copy link
Member

I think this is fixed with #1906 (it will be in EAP6 of Rider 2020.3), but I can't get the original issue to show a warning without adding [CanBeNull]. Can you please confirm the repro sample - how is someGameObject declared, etc.? I'm closing for now, but happy to reopen if it's not fixed.

@citizenmatt citizenmatt added this to the Rider 2020.3 milestone Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants