Skip to content

Commit b7646d9

Browse files
authored
Merge pull request #9385 from ygottschalk/fix/9384-wrong-type-from-is-long
2 parents e96a929 + f026226 commit b7646d9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,9 +1871,9 @@ private static function getIsAssertion(string $function_name): ?Assertion
18711871
return new IsType(new Atomic\TString());
18721872
case 'is_int':
18731873
case 'is_integer':
1874+
case 'is_long':
18741875
return new IsType(new Atomic\TInt());
18751876
case 'is_float':
1876-
case 'is_long':
18771877
case 'is_double':
18781878
case 'is_real':
18791879
return new IsType(new Atomic\TFloat());

tests/TypeReconciliation/TypeTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,32 @@ function foo(array $arr) : void {
12391239
strlen($s);
12401240
}',
12411241
],
1242+
'testIsIntAndAliasesTypeNarrowing' => [
1243+
'code' => '<?php
1244+
/** @var mixed $a */
1245+
$a;
1246+
/** @var never $b */
1247+
$b;
1248+
/** @var never $c */
1249+
$c;
1250+
/** @var never $d */
1251+
$d;
1252+
if (is_int($a)) {
1253+
$b = $a;
1254+
}
1255+
if (is_integer($a)) {
1256+
$c = $a;
1257+
}
1258+
if (is_long($a)) {
1259+
$d = $a;
1260+
}
1261+
',
1262+
'assertions' => [
1263+
'$b===' => 'int',
1264+
'$c===' => 'int',
1265+
'$d===' => 'int',
1266+
],
1267+
],
12421268
'narrowWithCountToAllowNonTupleKeyedArray' => [
12431269
'code' => '<?php
12441270
/**

0 commit comments

Comments
 (0)