mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Calculate more literal values (#5032)
* try to calculate more literal values * add test * improve test
This commit is contained in:
parent
7997766e8b
commit
72c21c5fa6
@ -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