mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Clean up static property reconciliation
This commit is contained in:
parent
6b56a0239d
commit
612f74f481
@ -401,9 +401,10 @@ class Reconciler
|
||||
&& $chars[$i + 2] === '$'
|
||||
) {
|
||||
++$i;
|
||||
++$i;
|
||||
|
||||
++$parts_offset;
|
||||
$parts[$parts_offset] = '->';
|
||||
$parts[$parts_offset] = '::$';
|
||||
++$parts_offset;
|
||||
continue 2;
|
||||
}
|
||||
@ -518,6 +519,8 @@ class Reconciler
|
||||
if ($has_isset) {
|
||||
$new_base_type_candidate->possibly_undefined = true;
|
||||
}
|
||||
} elseif ($existing_key_type_part instanceof Type\Atomic\TNull) {
|
||||
$new_base_type_candidate = Type::getNull();
|
||||
} elseif (!$existing_key_type_part instanceof Type\Atomic\ObjectLike) {
|
||||
return Type::getMixed();
|
||||
} elseif ($array_key[0] === '$' || ($array_key[0] !== '\'' && !\is_numeric($array_key[0]))) {
|
||||
@ -558,9 +561,9 @@ class Reconciler
|
||||
}
|
||||
|
||||
$base_key = $new_base_key;
|
||||
} elseif ($divider === '->') {
|
||||
} elseif ($divider === '->' || $divider === '::$') {
|
||||
$property_name = array_shift($key_parts);
|
||||
$new_base_key = $base_key . '->' . $property_name;
|
||||
$new_base_key = $base_key . $divider . $property_name;
|
||||
|
||||
if (!isset($existing_keys[$new_base_key])) {
|
||||
$new_base_type = null;
|
||||
@ -590,10 +593,6 @@ class Reconciler
|
||||
true
|
||||
);
|
||||
|
||||
$class_storage = $codebase->classlike_storage_provider->get(
|
||||
(string)$declaring_property_class
|
||||
);
|
||||
|
||||
$class_property_type = $codebase->properties->getPropertyType(
|
||||
$property_id,
|
||||
false,
|
||||
|
@ -2254,6 +2254,21 @@ class ConditionalTest extends \Psalm\Tests\TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'assertOnStaticPropertyOffset' => [
|
||||
'<?php
|
||||
class C {
|
||||
/** @var array<string, string>|null */
|
||||
private static $map = [];
|
||||
|
||||
public static function foo(string $id) : ?string {
|
||||
if (isset(self::$map[$id])) {
|
||||
return self::$map[$id];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -2601,6 +2616,24 @@ class ConditionalTest extends \Psalm\Tests\TestCase
|
||||
}',
|
||||
'error_message' => 'RedundantCondition',
|
||||
],
|
||||
'SKIPPED-catchRedundantConditionOnBinaryOpForwards' => [
|
||||
'<?php
|
||||
class App {}
|
||||
|
||||
function test(App $app) : void {
|
||||
if ($app || rand(0, 1)) {}
|
||||
}',
|
||||
'error_message' => 'RedundantCondition',
|
||||
],
|
||||
'SKIPPED-catchRedundantConditionOnBinaryOpBackwards' => [
|
||||
'<?php
|
||||
class App {}
|
||||
|
||||
function test(App $app) : void {
|
||||
if (rand(0, 1) || $app) {}
|
||||
}',
|
||||
'error_message' => 'RedundantCondition',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user