psalm
psalm copied to clipboard
Exponent operator should not trigger when operands are different type and `strictBinaryOperands` is enabled
$v = 1.5 ** 10;
This code triggers
ERROR: InvalidOperand - src.php:131:22 - Cannot add ints to floats (see https://psalm.dev/058)
$v = 1.5 ** 10;
while I believe it makes very little sense to demand both operands of ** be of the same type.
Hey @zerkms, can you reproduce the issue on https://psalm.dev ?
Note: requires strict binary operands option to be enabled.
This is a big issue when attempting to upgrade a project to Psalm 6, since this option is enabled by default. https://psalm.dev/r/a7932278f5
Of course I could suppress all InvalidOperand errors, but I think they would be helpful when the types are something other than float and int.
I found these snippets:
https://psalm.dev/r/a7932278f5
<?php
var_export(1.15 ** 7);
Psalm output (using commit cdceda0):
ERROR: InvalidOperand - 3:12 - Cannot process numeric types together in strict operands mode, please cast explicitly