Skip to content

Commit 47ff106

Browse files
Resolve bitwise not on constant integer
1 parent 6818997 commit 47ff106

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
@@ -2630,8 +2630,11 @@ public function getBitwiseNotTypeFromType(Type $exprType): Type
26302630

26312631
return TypeCombinator::intersect(...$accessories);
26322632
}
2633+
if ($type instanceof ConstantIntegerType || $type instanceof ConstantFloatType) {
2634+
return new ConstantIntegerType(~$type->getValue());
2635+
}
26332636
if ($type->isInteger()->yes() || $type->isFloat()->yes()) {
2634-
return new IntegerType(); //no const types here, result depends on PHP_INT_SIZE
2637+
return new IntegerType();
26352638
}
26362639
return new ErrorType();
26372640
});

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)