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

Fix support for bitwise or in constant expressions

This commit is contained in:
Matthew Brown 2020-03-09 00:54:26 -04:00
parent a5da866d97
commit 17afeae851
4 changed files with 20 additions and 3 deletions

View File

@ -1595,7 +1595,7 @@ class ClassLikes
|| $c instanceof UnresolvedConstant\UnresolvedSubtractionOp
|| $c instanceof UnresolvedConstant\UnresolvedDivisionOp
|| $c instanceof UnresolvedConstant\UnresolvedMultiplicationOp
|| $c instanceof UnresolvedConstant\UnresolvedBinaryOr
|| $c instanceof UnresolvedConstant\UnresolvedBitwiseOr
) {
if (($left instanceof Type\Atomic\TLiteralFloat || $left instanceof Type\Atomic\TLiteralInt)
&& ($right instanceof Type\Atomic\TLiteralFloat || $right instanceof Type\Atomic\TLiteralInt)
@ -1612,7 +1612,7 @@ class ClassLikes
return self::getLiteralTypeFromScalarValue($left->value / $right->value);
}
if ($c instanceof UnresolvedConstant\UnresolvedBinaryOr) {
if ($c instanceof UnresolvedConstant\UnresolvedBitwiseOr) {
return self::getLiteralTypeFromScalarValue($left->value | $right->value);
}

View File

@ -2,6 +2,6 @@
namespace Psalm\Internal\Scanner\UnresolvedConstant;
class UnresolvedBinaryOr extends UnresolvedBinaryOp
class UnresolvedBitwiseOr extends UnresolvedBinaryOp
{
}

View File

@ -3514,6 +3514,10 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\Concat) {
return new UnresolvedConstant\UnresolvedConcatOp($left, $right);
}
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BitwiseOr) {
return new UnresolvedConstant\UnresolvedBitwiseOr($left, $right);
}
}
if ($stmt instanceof PhpParser\Node\Expr\Ternary) {

View File

@ -750,6 +750,19 @@ class ConstantTest extends TestCase
}
}'
],
'bitwiseOrClassConstant' => [
'<?php
class X {
public const A = 1;
public const B = 2;
public const C = self::A | self::B;
}
$c = X::C;',
[
'$c' => 'int',
]
],
];
}