1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Allow Psalm to store unresolved Unary Ops

This commit is contained in:
orklah 2021-10-10 09:24:25 +02:00
parent f62c76a334
commit e7a86148b0
2 changed files with 49 additions and 0 deletions

View File

@ -195,6 +195,34 @@ class ExpressionResolver
return new UnresolvedConstant\ScalarValue($stmt->value);
}
if ($stmt instanceof PhpParser\Node\Expr\UnaryPlus) {
$right = self::getUnresolvedClassConstExpr(
$stmt->expr,
$aliases,
$fq_classlike_name,
$parent_fq_class_name
);
return new UnresolvedConstant\UnresolvedAdditionOp(
new UnresolvedConstant\ScalarValue(0),
$right
);
}
if ($stmt instanceof PhpParser\Node\Expr\UnaryMinus) {
$right = self::getUnresolvedClassConstExpr(
$stmt->expr,
$aliases,
$fq_classlike_name,
$parent_fq_class_name
);
return new UnresolvedConstant\UnresolvedSubtractionOp(
new UnresolvedConstant\ScalarValue(0),
$right
);
}
if ($stmt instanceof PhpParser\Node\Expr\Array_) {
$items = [];

View File

@ -1159,6 +1159,27 @@ class ConstantTest extends TestCase
'$arr===' => 'array{5: "a", 6: "aa", zz: "z"}',
],
],
'unresolvedConstWithUnaryMinus' => [
'<?php
const K = 5;
abstract class C6 {
public const M = [
1 => -1,
K => 6,
];
/**
* @param int $k
*/
public static function f(int $k): void {
$a = self::M;
print_r($a);
}
}',
],
];
}