Skip to content

Commit 05b6a26

Browse files
Resolve bitwise not on constant integer
1 parent c8a1ae1 commit 05b6a26

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
@@ -2159,8 +2159,11 @@ public function getBitwiseNotType(Expr $expr, callable $getTypeCallback): Type
21592159

21602160
return TypeCombinator::intersect(...$accessories);
21612161
}
2162+
if ($type instanceof ConstantIntegerType || $type instanceof ConstantFloatType) {
2163+
return new ConstantIntegerType(~$type->getValue());
2164+
}
21622165
if ($type->isInteger()->yes() || $type->isFloat()->yes()) {
2163-
return new IntegerType(); //no const types here, result depends on PHP_INT_SIZE
2166+
return new IntegerType();
21642167
}
21652168
return new ErrorType();
21662169
});

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)