psalm icon indicating copy to clipboard operation
psalm copied to clipboard

multiply or divide floats and ints: is it really an issue?

Open mathroc opened this issue 9 months ago • 3 comments

Psalm says "Cannot process ints and floats in strict binary operands mode, please cast explicitly"

but is that really an issue ?

https://psalm.dev/r/12263a8d9f

mathroc avatar Mar 28 '25 11:03 mathroc

I found these snippets:

https://psalm.dev/r/12263a8d9f
<?php

function f(int $a, float $b): float {
    return $a / $b;
}

function g(int $a, float $b): float {
    return $b / $a;
}

function h(int $a, int $b): float {
    return $a / $b;
}

function i(int $a, float $b): float {
    return $a * $b;
}

function j(int $a, float $b): float {
    return $b * $a;
}
Psalm output (using commit 2f8ed4d):

ERROR: InvalidOperand - 4:12 - Cannot process ints and floats in strict binary operands mode, please cast explicitly

ERROR: InvalidOperand - 8:12 - Cannot process ints and floats in strict binary operands mode, please cast explicitly

ERROR: InvalidOperand - 16:12 - Cannot process ints and floats in strict binary operands mode, please cast explicitly

ERROR: InvalidOperand - 20:12 - Cannot process ints and floats in strict binary operands mode, please cast explicitly

psalm-github-bot[bot] avatar Mar 28 '25 11:03 psalm-github-bot[bot]

Did you find a solution? Facing same issue.

jcvignoli avatar Apr 29 '25 20:04 jcvignoli

Did you find a solution? Facing same issue.

add a psalm-baseline.xml ... and ignore it.

DavidGoodwin avatar Oct 27 '25 16:10 DavidGoodwin