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

That new "Implicit check for Unity object lifetime" is nonsense #2461

Open
aybe opened this issue Sep 10, 2024 · 1 comment
Open

That new "Implicit check for Unity object lifetime" is nonsense #2461

aybe opened this issue Sep 10, 2024 · 1 comment

Comments

@aybe
Copy link

aybe commented Sep 10, 2024

Just noticed that new suggestion after upgrading today.

See by yourself, code was fine but applying either fix makes it worse actually:

New icon:

image

Fixes:

image

After fix 1:

image

After fix 2:

image

JetBrains ReSharper 2024.2.4
Build 242.0.20240905.115624 built on 2024-09-05
dotTrace 2024.2.20240905.115624
ReSharper C++ 2024.2.20240905.115624
ReSharper 2024.2.20240905.115624
JetBrains ForTea 2024.2.1.3 (Compatible)
JetBrains Unity 2024.2.3.166 (Compatible)

ReSharper 2024.2.4 licensed to aybe aybe. Subscription is valid through 1/16/2025. Perpetual for builds released before 1/17/2024.
ReSharper C++ 2024.2.4 licensed to aybe aybe. Subscription is valid through 1/16/2025. Perpetual for builds released before 1/17/2024.
TeamCity Add-in 2024.2.4 disabled by user preferences.

Build Version: 2024.2.4.65536

Visual Studio Enterprise 2022
Version 17.11.2, InstanceId a77197d5.
InstallVersion: 17.11.35222.181
InstallDir: “C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE”
LocalAppData: C:\Users\aybe\AppData\Local\Microsoft\VisualStudio\17.0_a77197d5

Branch: refs/heads/242.21829

Application Packages:
...
JetBrains Unity build 2024.2.3.166 on 0001-01-01

@waitxd
Copy link

waitxd commented Oct 25, 2024

First fix is valid. Casting UnityEngine.Object to bool is essentially a null-check, but shorter. Reference

So, in this case, Visual Studio's warning about null-dereferencing is invalid.

The second fix modifies code behavior by only checking the reference for null, ignoring the UnityEngine.Object lifetime.

Both context actions are applicable.

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