-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ParadoxicalCondition for no reason? #9552
Labels
Comments
I found these snippets: https://psalm.dev/r/268b76bdec<?php
/**
* @param non-empty-array<string, int> $measurement
* @param string $target_unit
*
* @return float
*/
function convert_scale_measurement_unit( $measurement, $target_unit ) {
if ( !in_array( $target_unit, array( 'g', 'kg', 'oz', 'lbs', 'lb' ), true ) ) {
$target_unit = 'g';
}
$measured_weight = 0;
foreach ( $measurement as $unit => $value ) {
if ( $unit === $target_unit ) {
$measured_weight += $value;
continue;
}
if ( $unit === 'lb' && $target_unit === 'kg' ) {
$value *= 0.45359237;
}
$measured_weight += $value;
}
return round( $measured_weight, 2 );
}
|
Looks like it happens with the value the last element of that array has. If I put |
I found these snippets: https://psalm.dev/r/7ebfb98ceb<?php
/**
* @param non-empty-array<string, int> $measurement
* @param string $target_unit
*
* @return float
*/
function convert_scale_measurement_unit($measurement, $target_unit) {
if (!in_array($target_unit, ['g', 'kg', 'oz', 'lb', 'lbs'], true)) {
$target_unit = 'g';
}
/** @psalm-trace $target_unit */;
$measured_weight = 0;
foreach ($measurement as $unit => $value) {
if ($unit === $target_unit) {
$measured_weight += $value;
continue;
}
if ($unit === 'lbs' && $target_unit === 'kg') {
$value *= 0.45359237;
}
$measured_weight += $value;
}
return round($measured_weight, 2);
}
|
kkmuffme
added a commit
to kkmuffme/psalm
that referenced
this issue
Dec 13, 2023
This was referenced Dec 13, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simplified code snippet https://psalm.dev/r/268b76bdec
No idea why/where it asserts that $unit cannot be "lb"?
=> when I comment the "continue;" the error is gone
=> this is ONLY with "lb". When I put "lbs" or anything else the error is gone too
This error is new in v5 (checked with v4 and it's not there)
The text was updated successfully, but these errors were encountered: