psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Greater > and Less Than < comparisons with non-numeric, non-string, non-resource types should report error

Open kkmuffme opened this issue 1 year ago • 3 comments

Fix https://github.com/vimeo/psalm/issues/10833

For int|null cases the errors could be slightly annoying, however null can refer to the minimum value (PHP_INT_MIN) but is compared as 0, or it refers to a non-numeric state and shouldn't be used in comparison in the first place (similar to what RiskyTruthyFalsyComparison checks, which I guess would apply here too, but I want to keep it simple for now)

kkmuffme avatar Mar 15 '24 20:03 kkmuffme

@jack-worman ready to be reviewed and merged

kkmuffme avatar Mar 16 '24 12:03 kkmuffme

Why allow comparing resources though?

weirdan avatar Mar 20 '24 05:03 weirdan

Because the docs say that that's fine, as they are converted to numbers and regular math applies: https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.types

kkmuffme avatar Mar 22 '24 19:03 kkmuffme