1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +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 GitHub
parent 7997766e8b
commit 72c21c5fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -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) {

View File

@ -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;