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

Keep HasArrayKey logic only for class strings

This commit is contained in:
Daniil Gentili 2022-12-02 22:07:26 +01:00
parent 4c47d50d91
commit a154d962f0
2 changed files with 18 additions and 28 deletions

View File

@ -75,6 +75,7 @@ use Psalm\Type\Union;
use function array_map;
use function array_merge;
use function assert;
use function count;
use function explode;
use function get_class;
@ -1903,34 +1904,21 @@ class SimpleAssertionReconciler extends Reconciler
$types = $existing_var_type->getAtomicTypes();
foreach ($types as &$atomic_type) {
if ($atomic_type instanceof TKeyedArray) {
$is_class_string = false;
assert(strpos($assertion, '::class') === (strlen($assertion)-7));
[$assertion] = explode('::', $assertion);
if (strpos($assertion, '::class')) {
[$assertion] = explode('::', $assertion);
$is_class_string = true;
}
if (isset($atomic_type->properties[$assertion])) {
$atomic_type = $atomic_type->setProperties(array_merge(
$atomic_type = new TKeyedArray(
array_merge(
$atomic_type->properties,
[
$assertion => $atomic_type->properties[$assertion]->setPossiblyUndefined(false)
]
));
} else {
$atomic_type = new TKeyedArray(
array_merge(
$atomic_type->properties,
[$assertion => Type::getMixed()]
),
$is_class_string ? array_merge(
$atomic_type->class_strings ?? [],
[$assertion => true]
) : $atomic_type->class_strings,
$atomic_type->fallback_params,
$atomic_type->is_list
);
}
[$assertion => Type::getMixed()]
),
array_merge(
$atomic_type->class_strings ?? [],
[$assertion => true]
),
$atomic_type->fallback_params,
$atomic_type->is_list
);
}
}
unset($atomic_type);

View File

@ -23,6 +23,7 @@ use Psalm\Storage\Assertion;
use Psalm\Storage\Assertion\ArrayKeyExists;
use Psalm\Storage\Assertion\Empty_;
use Psalm\Storage\Assertion\Falsy;
use Psalm\Storage\Assertion\HasArrayKey;
use Psalm\Storage\Assertion\HasIntOrStringArrayAccess;
use Psalm\Storage\Assertion\HasStringArrayAccess;
use Psalm\Storage\Assertion\IsEqualIsset;
@ -496,13 +497,14 @@ class Reconciler
}
}
/*if ($type[0][0] instanceof ArrayKeyExists) {
if ($type[0][0] instanceof ArrayKeyExists) {
$key_parts = self::breakUpPathIntoParts($nk);
if (count($key_parts) === 4
&& $key_parts[1] === '['
&& $key_parts[2][0] !== '\''
&& !is_numeric($key_parts[2])
&& strpos($key_parts[2], '::class') === (strlen($key_parts[2])-7)
) {
if ($key_parts[0][0] === '$') {
if (isset($new_types[$key_parts[0]])) {
@ -512,7 +514,7 @@ class Reconciler
}
}
}
}*/
}
}
}