Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2159,8 +2159,11 @@ public function getBitwiseNotType(Expr $expr, callable $getTypeCallback): Type

return TypeCombinator::intersect(...$accessories);
}
if ($type instanceof ConstantIntegerType || $type instanceof ConstantFloatType) {
return new ConstantIntegerType(~ (int) $type->getValue());
}
if ($type->isInteger()->yes() || $type->isFloat()->yes()) {
return new IntegerType(); //no const types here, result depends on PHP_INT_SIZE
return new IntegerType();
}
return new ErrorType();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bitwise-not.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ function foo(int $int, string $string, float $float, $stringOrInt, string $nonEm
assertType('int', ~$float);
assertType('int|string', ~$stringOrInt);
assertType("'" . (~"abc") . "'", ~"abc");
assertType('int', ~1); //result is dependent on PHP_INT_SIZE
assertType('-2', ~1);
}
Loading