mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #6635 from orklah/resolution_of_unary_ops
Resolution of unary ops
This commit is contained in:
commit
45ec0b36d4
@ -195,6 +195,42 @@ 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
|
||||
);
|
||||
|
||||
if (!$right) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
|
||||
if (!$right) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new UnresolvedConstant\UnresolvedSubtractionOp(
|
||||
new UnresolvedConstant\ScalarValue(0),
|
||||
$right
|
||||
);
|
||||
}
|
||||
|
||||
if ($stmt instanceof PhpParser\Node\Expr\Array_) {
|
||||
$items = [];
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user