You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
warning CS0252: Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'type'
Basically we could inadvertently be doing reference checks instead of value checks. The compiler suggests casting to a concrete class (since most of these are generic objects). But that introduces new risks, and complicates the checks. Switching to using .Equals on the known concrete class will, at worst do the same reference check, and at best do an value check. Plus it has the added bonus of clearing the compiler warnings.
I plan to resolve a bunch more warnings, but I figured splitting them up by warning type may be more likely to get at least some of them merged. I tried to prevent as many auto-format changes as possible (to prevent overcomplicating the changes), but a few whitespace ones slipped through.
I'm wary, these aren't the same. What happens if the result of AccessTools.Method is null?, suddenly you get null pointer exception whereas before it just failed the if case. The correct way to fix the warning is to do as it says, cast the side to a type. Or just use Object.Equals, it makes it less readable though.
I'm wary, these aren't the same. What happens if the result of AccessTools.Method is null?, suddenly you get null pointer exception whereas before it just failed the if case. The correct way to fix the warning is to do as it says, cast the side to a type. Or just use Object.Equals, it makes it less readable though.
You're right of course. I avoided the direct cast ((MethodInfo)inst.operand) for safety, just in case it was a different class. I assumed that the reflection result would exist. But assumptions make fools of us all...
I've updated it to cast using the syntax inst.operand as MethodInfo since this is safe against InvalidCastException and gone back to the == syntax.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feel free to reject, but the warnings are triggering me. This PR resolves 41 compiler warnings.
CS0252 warns:
Basically we could inadvertently be doing reference checks instead of value checks. The compiler suggests casting to a concrete class (since most of these are generic
objects). But that introduces new risks, and complicates the checks. Switching to using.Equalson the known concrete class will, at worst do the same reference check, and at best do an value check. Plus it has the added bonus of clearing the compiler warnings.I plan to resolve a bunch more warnings, but I figured splitting them up by warning type may be more likely to get at least some of them merged. I tried to prevent as many auto-format changes as possible (to prevent overcomplicating the changes), but a few whitespace ones slipped through.