1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

unparsable types

This commit is contained in:
orklah 2021-09-25 16:47:38 +02:00
parent 2f82f25934
commit b4e0f83186

View File

@ -3,26 +3,24 @@
namespace Psalm\Internal\Provider;
use PhpParser;
use PhpParser\Node;
use Psalm\Type\Union;
use SplObjectStorage;
class NodeDataProvider implements \Psalm\NodeTypeProvider
{
/** @var SplObjectStorage<PhpParser\Node, Union> */
/** @var SplObjectStorage<Node, Union> */
private $node_types;
/**
* @var SplObjectStorage<
* PhpParser\Node,
* list<non-empty-array<string, non-empty-list<non-empty-list<string>>>>|null
* >
* @var SplObjectStorage<Node,list<non-empty-array<string, non-empty-list<non-empty-list<string>>>>|null>
*/
private $node_assertions;
/** @var SplObjectStorage<PhpParser\Node, array<int, \Psalm\Storage\Assertion>> */
/** @var SplObjectStorage<Node, array<int, \Psalm\Storage\Assertion>> */
private $node_if_true_assertions;
/** @var SplObjectStorage<PhpParser\Node, array<int, \Psalm\Storage\Assertion>> */
/** @var SplObjectStorage<Node, array<int, \Psalm\Storage\Assertion>> */
private $node_if_false_assertions;
/** @var bool */
@ -37,7 +35,7 @@ class NodeDataProvider implements \Psalm\NodeTypeProvider
}
/**
* @param PhpParser\Node\Expr|PhpParser\Node\Name|PhpParser\Node\Stmt\Return_ $node
* @param Node\Expr|Node\Name|Node\Stmt\Return_ $node
*/
public function setType(PhpParser\NodeAbstract $node, Union $type) : void
{
@ -45,7 +43,7 @@ class NodeDataProvider implements \Psalm\NodeTypeProvider
}
/**
* @param PhpParser\Node\Expr|PhpParser\Node\Name|PhpParser\Node\Stmt\Return_ $node
* @param Node\Expr|Node\Name|Node\Stmt\Return_ $node
*/
public function getType(PhpParser\NodeAbstract $node) : ?Union
{
@ -55,7 +53,7 @@ class NodeDataProvider implements \Psalm\NodeTypeProvider
/**
* @param list<non-empty-array<string, non-empty-list<non-empty-list<string>>>>|null $assertions
*/
public function setAssertions(PhpParser\Node\Expr $node, ?array $assertions) : void
public function setAssertions(Node\Expr $node, ?array $assertions) : void
{
if (!$this->cache_assertions) {
return;
@ -67,7 +65,7 @@ class NodeDataProvider implements \Psalm\NodeTypeProvider
/**
* @return list<non-empty-array<string, non-empty-list<non-empty-list<string>>>>|null
*/
public function getAssertions(PhpParser\Node\Expr $node) : ?array
public function getAssertions(Node\Expr $node) : ?array
{
if (!$this->cache_assertions) {
return null;
@ -77,61 +75,49 @@ class NodeDataProvider implements \Psalm\NodeTypeProvider
}
/**
* @param PhpParser\Node\Expr\FuncCall
* |PhpParser\Node\Expr\MethodCall
* |PhpParser\Node\Expr\StaticCall
* |PhpParser\Node\Expr\New_ $node
* @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $node
* @param array<int, \Psalm\Storage\Assertion> $assertions
*/
public function setIfTrueAssertions(PhpParser\Node\Expr $node, array $assertions) : void
public function setIfTrueAssertions(Node\Expr $node, array $assertions) : void
{
$this->node_if_true_assertions[$node] = $assertions;
}
/**
* @param PhpParser\Node\Expr\FuncCall
* |PhpParser\Node\Expr\MethodCall
* |PhpParser\Node\Expr\StaticCall
* |PhpParser\Node\Expr\New_ $node
* @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $node
* @return array<int, \Psalm\Storage\Assertion>|null
*/
public function getIfTrueAssertions(PhpParser\Node\Expr $node) : ?array
public function getIfTrueAssertions(Node\Expr $node) : ?array
{
return $this->node_if_true_assertions[$node] ?? null;
}
/**
* @param PhpParser\Node\Expr\FuncCall
* |PhpParser\Node\Expr\MethodCall
* |PhpParser\Node\Expr\StaticCall
* |PhpParser\Node\Expr\New_ $node
* @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $node
* @param array<int, \Psalm\Storage\Assertion> $assertions
*/
public function setIfFalseAssertions(PhpParser\Node\Expr $node, array $assertions) : void
public function setIfFalseAssertions(Node\Expr $node, array $assertions) : void
{
$this->node_if_false_assertions[$node] = $assertions;
}
/**
* @param PhpParser\Node\Expr\FuncCall
* |PhpParser\Node\Expr\MethodCall
* |PhpParser\Node\Expr\StaticCall
* |PhpParser\Node\Expr\New_ $node
* @param Node\Expr\FuncCall|Node\Expr\MethodCall|Node\Expr\StaticCall|Node\Expr\New_ $node
* @return array<int, \Psalm\Storage\Assertion>|null
*/
public function getIfFalseAssertions(PhpParser\Node\Expr $node) : ?array
public function getIfFalseAssertions(Node\Expr $node) : ?array
{
return $this->node_if_false_assertions[$node] ?? null;
}
public function isPureCompatible(PhpParser\Node\Expr $node) : bool
public function isPureCompatible(Node\Expr $node) : bool
{
$node_type = $this->getType($node);
return ($node_type && $node_type->reference_free) || isset($node->pure);
}
public function clearNodeOfTypeAndAssertions(PhpParser\Node\Expr $node) : void
public function clearNodeOfTypeAndAssertions(Node\Expr $node) : void
{
unset($this->node_types[$node], $this->node_assertions[$node]);
}