1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Calculate more literal values (#5032)

* try to calculate more literal values

* add test

* improve test
This commit is contained in:
orklah 2021-01-17 16:55:32 +01:00 committed by Daniil Gentili
parent 2a682c1f36
commit 61b7975850
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 13 additions and 3 deletions

View File

@ -295,13 +295,14 @@ class NonDivArithmeticOpAnalyzer
&& $right_type_part instanceof TLiteralInt && $right_type_part instanceof TLiteralInt
&& ($left instanceof PhpParser\Node\Scalar && ($left instanceof PhpParser\Node\Scalar
|| $left instanceof PhpParser\Node\Expr\ConstFetch || $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\Scalar
|| $right instanceof PhpParser\Node\Expr\ConstFetch || $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! // time for some arithmetic!
$calculated_type = null; $calculated_type = null;
if ($parent instanceof PhpParser\Node\Expr\BinaryOp\Plus) { if ($parent instanceof PhpParser\Node\Expr\BinaryOp\Plus) {

View File

@ -196,6 +196,15 @@ class BinaryOperationTest extends TestCase
'$f' => 'string', '$f' => 'string',
], ],
], ],
'ComplexLiteralBitwise' => [
'<?php
/**
* @return 7
*/
function scope(){
return 1 | 2 | 4 | (1 & 0);
}',
],
'booleanXor' => [ 'booleanXor' => [
'<?php '<?php
$a = 4 ^ 1; $a = 4 ^ 1;