Skip to content
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

Fix crash when int range boundary is overflown #9260

Merged
merged 1 commit into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
use function count;
use function explode;
use function get_class;
use function is_int;
use function min;
use function strlen;
use function strpos;
Expand Down Expand Up @@ -2000,7 +2001,7 @@ private static function reconcileIsGreaterThan(
$existing_var_type->addType(new TIntRange($assertion_value, $atomic_type->value));
}
}*/
} elseif ($atomic_type instanceof TInt) {
} elseif ($atomic_type instanceof TInt && is_int($assertion_value)) {
$redundant = false;
$existing_var_type->removeType($atomic_type->getKey());
$existing_var_type->addType(new TIntRange($assertion_value, null));
Expand Down
13 changes: 13 additions & 0 deletions tests/IntRangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,19 @@ function bar(int $_a, int $_b): void {}
}
',
],
'rangeOverflow' => [
'code' => '<?php
$i = (int)ceil(1);
if ($i <= 9223372036854775807) {
$z = $i;
} else {
$z = null;
}
',
'assertions' => [
'$z' => 'int<min, 9223372036854775807>|null',
],
],
];
}

Expand Down