Skip to content

Commit 0b9da26

Browse files
Resolve bitwise not on constant integer
1 parent 1eead47 commit 0b9da26

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2594,8 +2594,11 @@ public function getBitwiseNotTypeFromType(Type $exprType): Type
25942594

25952595
return TypeCombinator::intersect(...$accessories);
25962596
}
2597+
if ($type instanceof ConstantIntegerType || $type instanceof ConstantFloatType) {
2598+
return new ConstantIntegerType(~$type->getValue());
2599+
}
25972600
if ($type->isInteger()->yes() || $type->isFloat()->yes()) {
2598-
return new IntegerType(); //no const types here, result depends on PHP_INT_SIZE
2601+
return new IntegerType();
25992602
}
26002603
return new ErrorType();
26012604
});

tests/PHPStan/Analyser/nsrt/bitwise-not.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ function foo(int $int, string $string, float $float, $stringOrInt, string $nonEm
1717
assertType('int', ~$float);
1818
assertType('int|string', ~$stringOrInt);
1919
assertType("'" . (~"abc") . "'", ~"abc");
20-
assertType('int', ~1); //result is dependent on PHP_INT_SIZE
20+
assertType('-2', ~1);
2121
}

0 commit comments

Comments
 (0)