mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
Calculate more literal values (#5032)
* try to calculate more literal values * add test * improve test
This commit is contained in:
parent
2a682c1f36
commit
61b7975850
@ -295,13 +295,14 @@ class NonDivArithmeticOpAnalyzer
|
||||
&& $right_type_part instanceof TLiteralInt
|
||||
&& ($left instanceof PhpParser\Node\Scalar
|
||||
|| $left instanceof PhpParser\Node\Expr\ConstFetch
|
||||
|| $left instanceof PhpParser\Node\Expr\ClassConstFetch)
|
||||
|| $left instanceof PhpParser\Node\Expr\ClassConstFetch
|
||||
|| $left instanceof PhpParser\Node\Expr\BinaryOp)
|
||||
&& ($right instanceof PhpParser\Node\Scalar
|
||||
|| $right instanceof PhpParser\Node\Expr\ConstFetch
|
||||
|| $right instanceof PhpParser\Node\Expr\ClassConstFetch)
|
||||
|| $right instanceof PhpParser\Node\Expr\ClassConstFetch
|
||||
|| $right instanceof PhpParser\Node\Expr\BinaryOp)
|
||||
) {
|
||||
// time for some arithmetic!
|
||||
|
||||
$calculated_type = null;
|
||||
|
||||
if ($parent instanceof PhpParser\Node\Expr\BinaryOp\Plus) {
|
||||
|
@ -196,6 +196,15 @@ class BinaryOperationTest extends TestCase
|
||||
'$f' => 'string',
|
||||
],
|
||||
],
|
||||
'ComplexLiteralBitwise' => [
|
||||
'<?php
|
||||
/**
|
||||
* @return 7
|
||||
*/
|
||||
function scope(){
|
||||
return 1 | 2 | 4 | (1 & 0);
|
||||
}',
|
||||
],
|
||||
'booleanXor' => [
|
||||
'<?php
|
||||
$a = 4 ^ 1;
|
||||
|
Loading…
Reference in New Issue
Block a user