mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Improve handling of assertions on static properties
This commit is contained in:
parent
d2b99cbe77
commit
6b56a0239d
@ -11,6 +11,7 @@ use function ksort;
|
||||
use Psalm\Codebase;
|
||||
use Psalm\CodeLocation;
|
||||
use Psalm\Internal\Analyzer\StatementsAnalyzer;
|
||||
use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer;
|
||||
use Psalm\Internal\Analyzer\TraitAnalyzer;
|
||||
use Psalm\Internal\Type\AssertionReconciler;
|
||||
use Psalm\Issue\DocblockTypeContradiction;
|
||||
@ -393,6 +394,21 @@ class Reconciler
|
||||
|
||||
continue 2;
|
||||
|
||||
case ':':
|
||||
if (!$brackets
|
||||
&& $i < $char_count - 2
|
||||
&& $chars[$i + 1] === ':'
|
||||
&& $chars[$i + 2] === '$'
|
||||
) {
|
||||
++$i;
|
||||
|
||||
++$parts_offset;
|
||||
$parts[$parts_offset] = '->';
|
||||
++$parts_offset;
|
||||
continue 2;
|
||||
}
|
||||
// fall through
|
||||
|
||||
case '-':
|
||||
if (!$brackets
|
||||
&& $i < $char_count - 1
|
||||
@ -578,11 +594,24 @@ class Reconciler
|
||||
(string)$declaring_property_class
|
||||
);
|
||||
|
||||
$class_property_type = $class_storage->properties[$property_name]->type;
|
||||
$class_property_type = $codebase->properties->getPropertyType(
|
||||
$property_id,
|
||||
false,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
$class_property_type = $class_property_type
|
||||
? clone $class_property_type
|
||||
: Type::getMixed();
|
||||
if ($class_property_type) {
|
||||
$class_property_type = ExpressionAnalyzer::fleshOutType(
|
||||
$codebase,
|
||||
clone $class_property_type,
|
||||
$declaring_property_class,
|
||||
$declaring_property_class,
|
||||
null
|
||||
);
|
||||
} else {
|
||||
$class_property_type = Type::getMixed();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$class_property_type = Type::getMixed();
|
||||
|
@ -2238,6 +2238,22 @@ class ConditionalTest extends \Psalm\Tests\TestCase
|
||||
echo isset($a);
|
||||
}'
|
||||
],
|
||||
'assertOnStaticClassKey' => [
|
||||
'<?php
|
||||
abstract class Obj {
|
||||
/** @var array<class-string, array<string, int>> */
|
||||
private static $arr = [];
|
||||
|
||||
/** @return array<string, int> */
|
||||
public static function getArr() : array {
|
||||
if (!isset(self::$arr[static::class])) {
|
||||
self::$arr[static::class] = ["hello" => 5];
|
||||
}
|
||||
|
||||
return self::$arr[static::class];
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user