neo-devpack-dotnet icon indicating copy to clipboard operation
neo-devpack-dotnet copied to clipboard

Optimize null checks when use `IsValid`

Open shargon opened this issue 1 year ago • 2 comments

I saw a lot of smart contracts that use this code

UInt160 hash = xxxxx;
Assert(hash != null  && hash.IsValid)

this should be optimized to remove the null check because is already done in IsValid

shargon avatar Mar 03 '25 10:03 shargon

from the syntax perspective, if hash is null, it should not be able to call IsValid.

Jim8y avatar Jun 20 '25 12:06 Jim8y

The problem is that we already did a null check in IsValid, so or it's redudant, or we optimize it

shargon avatar Jun 20 '25 13:06 shargon