Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/PHPStan/Analyser/nsrt/mixed-subtract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php // lint >= 8.0

namespace SubtractMixed;

use function PHPStan\Testing\assertType;

/**
* @param int|0.0|''|'0'|array{}|false|null $moreThenFalsy
*/
function subtract(mixed $m, $moreThenFalsy) {
if ($m !== true) {
assertType("mixed~true", $m);
assertType('bool', (bool) $m); // mixed could still contain something truthy
}
if ($m !== false) {
assertType("mixed~false", $m);
assertType('bool', (bool) $m); // mixed could still contain something falsy
}
if (!is_bool($m)) {
assertType('mixed~bool', $m);
assertType('bool', (bool) $m);
}
if (!is_array($m)) {
assertType('mixed~array', $m);
assertType('bool', (bool) $m);
}

if ($m) {
assertType("mixed~(0|0.0|''|'0'|array{}|false|null)", $m);
assertType('true', (bool) $m);
}
if (!$m) {
assertType("0|0.0|''|'0'|array{}|false|null", $m);
assertType('false', (bool) $m);
}
if (!$m) {
if (!is_int($m)) {
assertType("0.0|''|'0'|array{}|false|null", $m);
assertType('false', (bool)$m);
}
if (!is_bool($m)) {
assertType("0|0.0|''|'0'|array{}|null", $m);
assertType('false', (bool)$m);
}
}

if (!$m || is_int($m)) {
assertType("0.0|''|'0'|array{}|int|false|null", $m);
assertType('bool', (bool) $m);
}

if ($m !== $moreThenFalsy) {
assertType('mixed', $m);
Copy link
Contributor Author

@staabm staabm Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems the substraction logic atm cannot deal with "subtract more then falsy", as the type stays mixed.
(I think its a different unrelated bug)

assertType('bool', (bool) $m); // could be true
}
}