JetBrains / resharper-unity

Unity support for both ReSharper and Rider
Apache License 2.0
1.21k stars 134 forks source link

No null propagation warning for Unity Objects #2448

Closed Heroshrine closed 3 months ago

Heroshrine commented 3 months ago

image

In the above image, a?. should provide a warning to not use null propagation, since it is a Unity Object.

Unity Editor version 6000.0.4f1, JetBrains Rider Editor package version 3.0.28.

citizenmatt commented 3 months ago

The "bypass lifetime check" inspections have changed in 2024.1. Instead of showing a warning when using ?. or ??, we now show a hint for == and !=.

The main reason for this is that there were many scenarios when the inspections weren't working, e.g. GetSomething()?.whatever would not be highlighted. We fixed all of these scenarios, but now it's too noisy - we're showing a lot of highlights telling you that something is working like normal C# code.

So we changed the inspection to show a highlight for when code was doing something other than normal C# code, i.e. for Unity objects' overridden == and != operators.

It's possible to re-enable the old inspections - go to Settings | Editor | Inspection Settings | Inspection Severity | C# and look for "Possible unintended bypass of lifetime check" in the Unity section (you can just search for this too).

Heroshrine commented 3 months ago

Ok, I did see a warning for == and !=, but it suggested to use if(!object) and (object) for performance, but both ==/!= and if(object)/if(!object) call the same underlying method, so I'm not sure if it should be suggesting that. Not sure if it's related.